This topic has not yet been rated - Rate this topic

5.1.2 Exception-Handling Overview

Visual Studio 6.0

When an exception occurs (is raised), the normal flow of control in the current thread is interrupted, the context is saved, and control is transferred to the exception-handling support code. This support code marshals the exception information and then enters a section of the support code called the exception dispatcher. The exception dispatcher searches for exception handlers and invokes them in the proper sequence.

When a handler is invoked, it is called as a procedure with arguments that describe the nature of the exception, the environment within which the exception was raised, and the environment within which the handler was established. When the handler is called the exception is said to be delivered to the handler.

The handler may respond to the exception in several ways, including various combinations of the following:

  • Perform some action that affects the context of the thread (possibly correcting the circumstances that led to the exception being raised).

  • Modify or augment the description of the exception.

  • Raise a nested exception, causing another exception to occur in the context of the exception handler or in a procedure called directly or indirectly by the handler.

When an exception handler has finished processing an exception, it must indicate this in one of the following ways:

  • Indicate that the exception-handling support code should reraise the exception and resume the search for another handler.

  • Indicate that the exception-handling support code should continue execution of the interrupted thread at the location indicated by the saved exception program counter.

  • Unwind, which causes the exception-handling support code to resume execution of the thread at a point different than the point at which it was interrupted, or terminate the execution of the thread.

All exceptions are handled with the same interfaces, data structures, and algorithms. That is, there is unified exception handling for all kinds of exceptions, regardless of their origination.

Each exception has an exception value that identifies the exception (such as subscript range violation, or memory access control violation). Exceptions may also have associated with them one or more exception qualifiers (such as the name of an array and the subscript that was out of range, or an address associated with a memory access control violation).

Did you find this helpful?
(1500 characters remaining)