Signals and Exceptions

IBM C and C++ Compilers and the operating system under which it runs both have the capability to detect and report run-time errors and abnormal conditions. Your application can detect them as signals or exceptions, and by handling them, terminate gracefully or recover and continue execution.

IBM C and C++ Compilers supports the following mechanisms for signals and exceptions:

Signals
Signals are facility built on operating exceptions defined by ANSI C. You can use them in C and C++ to intercept operating system exceptions in a portable way. Different signals differentiate between error conditions. The following kinds of events raise signals:

Operating System Exceptions
The operating system throws exceptions when certain abnormal conditions occur. The IBM C and C++ Compilers library provides a C-language exception handler, _Exception, to map operating exceptions to C signals and signal handlers. Instead of using _Exception in your application, you can create and use your own exception handlers.

Operating system exceptions are synchronous or asynchronous depending on the relationship between their cause and the execution of the program.

For more information on operating system exceptions and exception handlers, see the documentation for your operating system.

C++ Exception Handling
C++ exceptions constructs, such as try, throw and catch, exist only within the C++ language. IBM C and C++ Compilers implements C++ exception handling using the exception-handling facility of the operating system. However, C++ exception handlers cannot intercept operating system exceptions, such as access violations.

Structured Exception Handling
C Structured Exception Handling provides constructs similar to C++ try blocks to capture operating system exceptions in C code.



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


Choose Signal or Exception Handlers
Program Signal Handling
Write or Register a Signal Handler
Write or Register an Exception Handler
Handle Floating-Point Exceptions
Get a Machine-State Dump


Asynchronous Exceptions
Critical Functions
Default Signal Handlers
Default Exception Handling (OS/2)
Default Exception Handling
Exception Handling for Floating-Point Exceptions
Exception Information Provided by OS/2
OS/2 APIs that Interfere with Exception Handling
Floating-Point Bit Masks
Signal and Exception Handling Considerations
Example of a C Signal Handler
Example of a Windows Machine-State Dump
Example of an OS/2 Exception Handler
Example of volatile Variables in a Signal Handler