Error Handlers
The Essential Math Module uses the macro RWTHROW to throw an exception. If your compiler supports exceptions, this macro resolves by calling a function that throws the exception. If your compiler does not support exceptions, the macro resolves to call an error handler with prototype:
void errHandler(const RWxmsg&);
The default error handler aborts the program. You can change the default handler with the function:
typedef void (*rwErrHandler)(const RWxmsg&);
rwErrHandler rwSetErrHandler(rwErrHandler);
The next example demonstrates how a user-defined error handler works in a compiler that doesn't support exceptions:
#include <rw/rwerr.h>
#include <rw/coreerr.h>
#include <iostream.h>
#ifdef RW_NO_EXCEPTIONS
void myOwnErrorHandler(const RWxmsg& error){
cout << "myOwnErrorHandler(" << error.why() << ")" << endl;
}
int main(){
rwSetErrHandler(myOwnErrorHandler); // Comment out this line
// to get the default
// error handler.
RWTHROW( RWExternalErr("Error!"));
cout << "Done." << endl;
return 0;
}
#else //RW_NO_EXCEPTIONS
#error This example only for compilers without exception handling
#endif