A catastrophe mechanism for coronal mass ejections