### Default Exception Handling (OS/2)

The IBM C and C++ Compilers library provides a default exception handling function, _Exception. This function is the C language exception handler. By default, _Exception is registered automatically for every process or thread launched by functions provided by IBM C and C++ Compilers. The default handler maps recognized OS/2 exceptions to C signals, which are then passed by the run-time library to the appropriate signal handlers.

Here is the prototype for _Exception:

>     #include <os2.h>

>     unsigned long _System _Exception(EXCEPTIONREPORTRECORD * report_rec,
>                                      EXCEPTIONREGISTRATIONRECORD * reg_rec,
>                                      CONTEXTRECORD * exc,
>                                      void * dummy);

The table below shows which types of OS/2 exceptions are recognized by _Exception, the names of the exceptions, and the C signals to which each exception type is mapped. These are the only OS/2 exceptions handled by _Exception. The table also shows whether the program can continue if the corresponding signal handler is SIG_IGN or if a user-defined signal handler returns. A No means that the program terminates unless the signal has a handler that calls longjmp to jump to transfer control.

If the signal handler value is set to SIG_DFL, the default action taken for each of these exceptions is to terminate the program with an exit code of 99.

OS/2 Exception | C Signal | Continuable?
--- | --- | ---
Divide by zero XCPT_INTEGER_DIVIDE_BY_ZERO | SIGFPE | No
NPX387 error XCPT_FLOAT_DENORMAL_OPERAND XCPT_FLOAT_DIVIDE_BY_ZERO XCPT_FLOAT_INEXACT_RESULT XCPT_FLOAT_INVALID_OPERATION XCPT_FLOAT_OVERFLOW XCPT_FLOAT_STACK_CHECK XCPT_FLOAT_UNDERFLOW | SIGFPE | No, except for XCPT_FLOAT_INEXACT_RESULT
Overflow occurred XCPT_INTEGER_OVERFLOW | SIGFPE | Yes, resets the overflow flag
Bound opcode failed XCPT_ARRAY_BOUNDS_EXCEEDED | SIGFPE | No
Opcode not valid XCPT_ILLEGAL_INSTRUCTION XCPT_INVALID_LOCK_SEQUENCE XCPT_PRIVILEGED_INSTRUCTION | SIGILL | No
General Protection fault XCPT_ACCESS_VIOLATION XCPT_DATATYPE_MISALIGNMENT | SIGSEGV | No
Ctrl-Break XCPT_SIGNAL (XCPT_SIGNAL_BREAK) | SIGBREAK | Yes
Ctrl-C XCPT_SIGNAL (XCPT_SIGNAL_INTR) | SIGINT | Yes
End process XCPT_SIGNAL(XCPT_SIGNAL_KILLPROC) | SIGTERM | Yes

Signals and Exceptions

Write or Register an Exception Handler
Register an OS/2 Exception Handler Using OS/2 APIs

Default Signal Handlers
Exception Information Provided by OS/2
Prototype of an OS/2 Exception Handler
How OS/2 Chains Exception Handlers