MATLAB: What exceptions are thrown by MEX API functions in MATLAB 7.0 (R14)

MATLAB

I have written a MEX function in C++ that uses try/catch error handling. I am catching some exceptions that seem to be thrown by MEX API functions.
For example when I compile and execute the following code MEX-code
#include "mex.h"
extern "C" void mexFunction(int nlhs, mxArray*plhs[], int nrhs, const mxArray*prhs[]){
try {
mexErrMsgTxt("error message");
}
catch (...) {
mexPrintf("An exception was thrown.\n");
}
}
it produces the following output
??? error message
an exception is thrown.

Best Answer

The ability to identify the exceptions thrown by MEX API functions is not available in MATLAB 7.0 (R14).
Starting in MATLAB 7.0 (R14) the C/C++ MEX API functions throw C++ exceptions. The exceptions, however, are generic, unpublished, and likely to change in future versions of the API. All MEX API functions have the possibility of throwing exceptions.
It is recommended that you write code which does not try to catch exceptions thrown by MEX API functions.
For example, instead of using the "catch all exceptions" syntax
catch(...)
specify the class of the exception you want to catch.
catch(const MyExceptionClass & e)