Using the C++ Math Library | ![]() ![]() |
Replacing the Default Library Error Handler
The default error handling behavior of the MATLAB C++ Math Library routines is implemented by the default library error handler routine. You can customize error handling by replacing the default library error handler routine with one of your own design.
Note If your compiler supports exceptions, the error handler is only called for warning-level errors. For all other errors, a C++ exception is thrown. |
To replace the default error handler you must:
Writing an Error Handler
When you write an error handler, you must conform to the library prototype for error handling routines:
void MyErrorHandler( const char *msg, bool isError ) { if(isError) // Will always be false if exceptions supported { // Process Error } else { // Process Warning } }
In this prototype, note the following:
const
string and a Boolean value. The string is the text of the error message. When the value of this Boolean value is TRUE
, it indicates an error message. If this value is FALSE
, it indicates a warning message.Registering Your Error Handler
After writing an error handler, you must register it with the MATLAB C Math Library so that the library routines can call it when they encounter an error condition at runtime. You register an error handler using the mwSetErrorMsgHandler()
routine.
mwSetErrorMsgHandler(MyErrorHandler);
![]() | Example Program: Handling Exceptions (ex5.cpp) | Exception Handling in the MATLAB C++ Math Library | ![]() |