An application uses DosSetExceptionHandler to register its own exception handling routines. More than one routine can be registered; the last routine registered will be called first.

One or more exception handlers can be registered for each thread in a process. Moreover, exception handlers can be specified not only for system exceptions, but also for user-defined exceptions that are anticipated for a particular thread.

Only Process Termination exceptions are sent to all threads in a process. Other exceptions (synchronous exceptions) are sent only to the exception handler registered for the thread where the exception occurred. The application must register an exception handler for each thread that is handling exceptions.

The following code fragment shows how an application registers an exception handling routine:

    #define INCL_BASE
    #define INCL_DOSEXCEPTIONS
    #include <os2.h>

    ULONG _System myHandler(PEXCEPTIONREPORTRECORD,
                           PEXCEPTIONREGISTRATIONRECORD,
                           PCONTEXTRECORD,
                           PVOID);

    VOID main(VOID)
    {
        EXCEPTIONREGISTRATIONRECORD xcpthand = { 0, &myHandler };

        DosError(FERR_DISABLEEXCEPTION | FERR_DISABLEHARDERR);

        DosSetExceptionHandler(&xcpthand);

        /*
         .
         . Other processing occurs here; myHandler will handle the exceptions.
         .
         */

        DosUnsetExceptionHandler(&xcpthand);
    }

If a procedure registers an exception handler, it must deregister the handler by calling DosUnsetExceptionHandler before returning.

Note:


[Back] [Next]