All OS/2 exception handlers conform to the prototype for MyExceptHandler shown below. You can use such a handler alone, or with the IBM C and C++ Compilers default handler, _Exception.
#define INCL_BASE
#include <os2.h>
APIRET APIENTRY MyExceptHandler(EXCEPTIONREPORTRECORD *,
EXCEPTIONREGISTRATIONRECORD *,
CONTEXTRECORD *,
PVOID dummy);
The structures passed as parameters are updated by OS/2 and provide your function with information about the exception. They are defined in the OS/2 header file <bsexcpt.h>.
The types and linkage convention used in the prototype are as follows:
| Keyword | Description |
|---|---|
| APIRET | Specifies the return type
of the function. If you return from your exception
handler, you must return one of the following two values:
|
| APIENTRY | Defines the function
linkage. The OS/2 header files found in the
IBMCXXO\INCLUDE\OS2 directory header files define
APIENTRY as _System linkage. Use the APIENTRY keyword rather than specifying the linkage type yourself. Note that your exception handler must be an external function; it cannot be static. |
| EXCEPTIONREPORTRECORD * | Points to a structure that contains high-level information about the exception. |
| EXCEPTIONREGISTRATIONRECORD * | Points to the record that registered the exception handler. The address of the record is always on the stack. |
| CONTEXTRECORD * | Points to a structure
that contains information about the state of the thread
at the time of the exception, including the register contents and the state of the floating-point unit and flags. When an exception handler returns XCPT_CONTINUE_EXECUTION, the machine state is reloaded from this structure. You should only modify the contents of this structure if you are sure your exception handler will return XCPT_CONTINUE_EXECUTION. |
| PVOID | Is a pointer to void that you must pass back unchanged to the operating system. |
![]()
Write or Register an Exception
Handler
Register an OS/2 Exception Handler
Using OS/2 APIs
![]()
OS/2 Exceptions and Default Handling
Exception
Information Provided by OS/2
OS/2 APIs That
Interfere with Exception Handling
Example of an OS/2 Exception
Handler