### Signal and Exception Handling

You can handle signals and operating system exceptions in any of the following ways:

- Accept the default exception handling provided by IBM C and C++ Compilers, which usually results in program termination with a message.
- Program signal handling in C and C++ programs.
- Use exception handlers. When you do this, you override the IBM C and C++ Compilers exception handler, _Exception, which maps operating system exceptions to C signals and signal handlers.
- Use C Structured Exception Handling, which provides the same functions as operating system exceptions do, but with simpler syntax.

When to Simply Debug
To eliminate exceptions that you suspect are due to program logic, use the debugger. For example, you should correct code that causes a divide by 0 exception, rather than programming a handler for that condition. The debugger provides complete notification and stack tracing is available.

Here are some other common problems:

- Improper use of memory. Using a pointer to an object that has already been freed can cause an exception. In such situations, try rebuilding your program using the /Tm compiler option.
- Using an invalid pointer.
- Passing an invalid parameter to a system function.
- Return codes from library or system calls that are not checked.

For diagnostic purposes you can build your program with the /Tx compiler option.

Signals and Exceptions
Signal and Exception Handlers in DLLs
Signals and Exceptions in Critical Functions
Run-Time Library Environments
C++ Exception Handling

Program Signal Handling
Write or Register a Signal Handler
Write or Register an Exception Handler
Register an Exception Handler Using OS/2 APIs
Register an Exception Handler Using Preprocessor Directives
Get a Machine-State Dump

Asynchronous Exceptions
Signals and Default Handlers
OS/2 Exceptions and Default Handling
Windows Exceptions and Default Handling
Exception Information Provided by OS/2
Prototype of an OS/2 Exception Handler
OS/2 APIs That Interfere with Exception Handling
Example of an OS/2 Exception Handler
Exception Handling for Floating-Point Exceptions
Signal and Exception Handlers in Multithreaded Programs
Critical Functions
Floating-Point Bit Masks
Signal-Handling Considerations
Example of a Windows Machine-State Dump