catch the error thrown by fmincon in NonlinearProgram

Solves #549