Exception Handling

The following outcomes are possible when a memory object is referenced by the application:

  • If the memory has not been allocated or committed, a general protection exception (Trap 000D) will occur.

  • If the memory has been allocated but not committed, a page fault exception (Trap 000E) will occur.

    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.

  • If the page to be referenced has been defined as a guard page, a guard page exception is generated. If the application has not registered its own handler for this exception, the system's default handler will commit the page, and mark the next page in the memory object as the new guard page for the object. Once the guard page exception has been processed, execution proceeds normally.

  • If none of the above conditions occur, the memory object is accessed and execution proceeds normally.

    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.


    [Back: Suballocating Memory]
    [Next: Shared Memory Objects]