The following outcomes are possible when a memory object is referenced by the application:
In both of the above cases, the exception is reported to the application's general protection exception handler, if one has been registered by the application. The application may then deal with the error. If an exception handler has not been registered by the application, the default exception handler provided by the operating system will terminate the application.
Exception handlers for the various types of exception may be registered using the DosSetExceptionHandler() function, as shown in Figure "Registering a Guard Page Exception Handler".
Note that unlike previous versions of OS/2, application handlers need not be written in assembly language; high-level programming languages may be used.
Exception handlers are registered on a per-thread basis, and multiple exception handlers may be registered for each thread. When more than one exception handler is registered, the handlers are chained, with the most recent addition being placed at the start of the chain. When an exception occurs, control is passed to the first handler, which may handle the exception and return XCPT_CONTINUE_EXECUTION, in which case the operating system returns control to the application.
If the exception handler cannot handle a particular exception, it returns XCPT_CONTINUE_SEARCH, in which case the operating system passes control to the next exception handler in the chain. In this way, control is eventually passed to the operating system's default exception handlers.
When an exception handler is no longer required, it can be removed from the chain using the DosUnsetExceptionHandler() function.
Exception handling and the various operating system exceptions that can occur are described in the IBM OS/2 Version 2.0 Control Program Reference.