Opened 4 years ago

Closed 3 months ago

#252 closed defect (migrated)

C++ exceptions and MATLAB

Reported by: drosos.kourounis Owned by: ipopt-team
Priority: normal Component: Ipopt
Version: 3.11 Severity: normal
Keywords: Cc:


Dear developers,

according to the following thread,

C++ exceptions are not portable in MATLAB. As a result, every time IPOPT throws an exception MATLAB crashes. Is there any possible way to deactivate them during configuring or compilation? I searched the corresponding source files but I did not see any #define statements to remove exceptions in a preprocessing step. Compiling with -fno-exceptions doesn't work either.

Thanks in advance! DK.

Change History (4)

comment:1 Changed 4 years ago by kelman

It might be worth trying to use the C interface to Ipopt, I haven't looked at the code in a while but I'm pretty sure the mex wrapper is based on the C++ API. The C API is supposed to catch exceptions internally and not propagate them back to the calling function, which may or may not help with the Matlab crashes. I don't think completely removing exceptions from Ipopt would be possible, but I could be wrong. If using Ipopt from any environment other than Matlab is remotely feasible for you, I would recommend doing that.

comment:2 Changed 4 years ago by FabiF1

Hi DK,

If you're using Matlab, I would expect you to have written a mex-file. If that is true, wouldn't it be possible to implement a "Try-Catch" that would surround the call to ipopt, and if any error "known" or "unknown" is caught, then exit properly the mex-file with a:

mexprintf('Oupsss... Ipopt mexfile exits!')

You can also improve it by catching specific error and react differently.

Nonetheless this should enable you not to take down Matlab when a C++ exception is thrown.

Cheers, Fab

comment:3 Changed 4 years ago by kelman

There is a pre-existing mex file in Ipopt/contrib/MatlabInterface, that's what DK is using. I haven't looked through the code in some time, it may already be doing some try/catch internally. But it could probably be made more robust.

comment:4 Changed 3 months ago by stefan

  • Resolution set to migrated
  • Status changed from new to closed

This ticket has been migrated to GitHub and will be followed up there:

Note: See TracTickets for help on using tickets.