Signal and Exception Handling

Under previous versions of OS/2, signals were dispatched from a number of sources and were used to interrupt executing processes. These signals included Ctrl-C, Ctrl-Break, and signals generated by the DosKillProcess() function call.

Under OS/2 Version 2.0, signal handling has been merged with exception handling to provide a general, portable mechanism for handling all such events. OS/2 Version 2.0 provides four new system functions for exception handling on a per-thread basis:

  • DosRaiseException()

  • DosSetExceptionHandler()

  • DosUnsetExceptionHandler()

  • DosUnwindException().

    The DosSetSignalExceptionFocus() function is used to allow 32-bit applications to inform the operating system that they are to be the focus for Ctrl+Break and Ctrl-C signals. However, these signals are dispatched and treated as exceptions.

    Applications may register their own routines using the DosSetExceptionHandler() function to handle specific types of exceptions, including general protection exceptions which could not be trapped by applications under previous versions of OS/2. These exception handlers may be written in high-level languages such as "C"; they are not required to be written in assembly language, as was the case with previous versions of OS/2.

    One significant difference in exception handling between OS/2 Version 2.0 and previous versions of OS/2 is the ability, under Version 2.0, to handle general protection exceptions within the application. Under previous versions, such exceptions invariably resulted in application termination with a Trap 000D error; with Version 2.0 however, an application may recover or at least terminate in an orderly manner.

    The generalized exception-handling approach has several advantages:

  • Exception handlers may be chained and/or nested, and each handler may decide whether or not to pass an exception to subsequent handlers.

  • Exception handlers under OS/2 Version 2.0 may be written entirely in a high-level programming language; assembly language routines are not required. This reduces the dependence on the Intel 80386 architecture, and facilitates porting applications to other operating system and hardware platforms.

    Note that OS/2 Version 2.0 does not allow applications to register an exception handler for a "coprocessor not found" exception. Instead, the operating system itself traps such exceptions and provides transparent floating-point emulation on a per-thread basis.

    Note that OS/2 Version 2.0 provides its own exception handlers within the service layers for all 32-bit system functions. These exception handlers allow the service routines to recover from page fault exceptions and general protection exceptions encountered due to bad pointers in applications' function calls. The function call returns an ERROR_BAD_PARAMETER code rather than a Trap 000D or Trap 000E code, thereby allowing the application to more easily recover from the error. This recoverability represents a significant enhancement over previous versions of OS/2, since it allows easier debugging and more flexible pointer handling, without the necessity for application-registered exception handlers to process these exceptions.

    Exception handling within applications is described in detail in OS/2 Version 2.0 - Volume 4: Application Development. The reader will also find programming examples of other topics, covered in this chapter, in that volume.


    [Back: Interrupt Handling]
    [Next: Thread Management]