The application is responsible for the creation and registration of the EXCEPTIONREGISTRATIONRECORD data structure. This is the data structure used by the application when it established the exception handler on the chain.

The only restrictions are that each pointer in the linked list must either point directly to the next pointer in the list or contain END_OF_CHAIN (-1), and the field immediately following the pointer field must be the pointer to the exception handler code. No fields other than these two will be examined by OS/2. The application can keep any state information that it chooses in this data structure, as long as it does not alter either of the fields used by the system.

When a procedure begins, it must create an EXCEPTIONREGISTRATIONRECORD on the stack, fill in the pointer to the exception handler routine, and link the data structure to the front of the exception handler chain by calling DosSetExceptionHandler.

Similarly, when the procedure ends, it must remove EXCEPTIONREGISTRATIONRECORD from the chain by calling DosUnsetExceptionHandler. This maintains the necessary frame-exception handler correspondence.

Note:

For the benefit of assembly language programmers, the Thread Information Block (TIB) is located at FS:[0]. This speeds access to the TIB data structure.

Because the FS is used to point to the TIB, applications that use the FS register must restore the original value when they are finished. Exception handling depends on the FS register pointing to the TIB.

EXCEPTIONREGISTRATIONRECORD data structure must be created on the stack of the application. That is, it must be a data structure that is local to the routine that registers the exception handler. It cannot be stored in the application's data segment. The reason for this is that OS/2 must be able to determine the relative ordering of ExceptionRegistration records by examining their addresses.