Customizing Error Handling

When an error occurs within any of the SOM-supplied methods or functions, an error-handling procedure is invoked. The default error-handling procedure supplied by SOM, pointed to by the global variable SOMError, has the following signature:

void (*SOMError) (int errorCode , string fileName, int lineNum );

The default error-handling procedure inspects the errorCode argument and takes appropriate action, depending on the last decimal digit of errorCode (see "Exceptions and error handling" in Using SOM Classes in Client Programs for a discussion of error classifications). In the default error handler, fatal errors terminate the current process. The remaining two arguments (fileName and lineNum), which indicate the name of the file and the line number within the file where the error occurred, are used to produce an error message.

An application programmer might wish to replace the default error handler with a customized error-handling routine to:

An application program would use code similar to the following to install the replacement routine:

#include <som.h>/* Define a replacement routine: */
void myErrorHandler (int errorCode, string fileName, int lineNum)
{
     (Customized code goes here)
}
...
/* After the next stmt all errors */
/* will be handled by the new routine   */
SOMError = myErrorHandler;

When any error condition originates within the classes supplied with SOM, SOM is left in an internally consistent state. If appropriate, an application program can trap errors with a customized error-handling procedure and then resume with other processing. Application programmers should be aware, however, that all methods within the SOM run-time library behave atomically. That is, they either succeed or fail; but if they fail, partial effects are undone wherever possible. This is done so that all SOM methods remain usable and can be re-executed following an error.


[Back: Customizing Character Output]
[Next: Customizing Mutual Exclusion Services (Thread Safety)]