Register an Exception Handler using OS/2 APIs

You can register your own OS/2 exception handler using the DosSetExceptionHandler and DosUnsetExceptionHandler APIs. To do this, declare your own EXCEPTIONREGISTRATIONRECORD structure to contain OS/2 exception information as shown in the following example:

#define INCL_BASE
#include <os2.h>

                                   /* the prototype for the exception handler */
APIRET APIENTRY MyExceptionHandler(EXCEPTIONREPORTRECORD *,
                                   EXCEPTIONREGISTRATIONRECORD *,
                                   CONTEXTRECORD *,
                                   PVOID);
int myfunction(...)
{
   EXCEPTIONREGISTRATIONRECORD err = { NULL,MyExceptionHandler };

   DosSetExceptionHandler(&err);   /* register */
   .
   .
   .
   DosUnsetExceptionHandler(&err); /* deregister */
}

You must deregister the exception handler before the function ends. Otherwise, the next exception that occurs on the thread can have unexpected and undefined results.



Signals and Exceptions
Signal and Exception Handling


OS/2 APIs That Interfere with Exception Handling
Example of an OS/2 Exception Handler
How OS/2 Chains Exception Handlers