## Presentation Device Driver Reference for OS/2

[prev][next][parent][TOC]

### Per-Thread Exception Management

Per-thread exception management is available to 32-bit EXEs, DLLs, and presentation drivers. The per-thread exception management model is a superset of DosExitList processing found in 16-bit OS/2 programming.

Under 16-bit OS/2 architecture, a process cannot handle access violations. In the event of an access violation, the system terminates the process. Given that the trapping process had registered an exit-list function, it had one final chance to do clean up just prior to termination. Sixteen-bit drivers and DLLs usually add an exitlist. At process termination, 16-bit drivers perform per-process clean up in exit-list functions.

Programmers of 32-bit drivers have a choice concerning per-process clean up . They may use the 32-bit version of DosExitList(), or they may add code for the DLL termination case in the driver function _DLL_InitTerm(). The _ DLL_InitTerm() function, if present and exported from the driver, will be called by OS/2 with parameter 0 on DLL instantiation and parameter 1 on DLL termination or unload. The _DLL_InitTerm() function provides process- granular clean up.

Furthermore, 32-bit OS/2 has exception handlers that are thread-granular. OS/2 lets each thread in a process handle exceptions that arise on that thread. Some of these exceptions are:

Accessing invalid or uncommitted memory
Stack overruns
Thread terminations
Floating point errors
Asynchronous (external) signals
User-raised exceptions (synchronous signals)
Invalid opcodes
Bounds
Divide by zero errors
Overflow errors

The goals of a 32-bit driver that uses exception management are:

When passed bad parameters that cause exceptions, drivers can call WinSetErrorInfo and return suitable result codes for the application to inspect.

When threads are terminated while executing driver code, the driver can clean up before the thread exits.