Transferring Control

C++ implements the termination model of exception handling. In the termination model, when an exception is thrown, control never returns to the throw point. The throw point is the point in program execution where the exception occurred.

C++ exception handling does not implement the resumption model of exception handling, which allows an exception handler to correct the exception and then return to the throw point.

When an exception is thrown, control is passed out of the throw expression and out of the try block that anticipated the exception. Control is passed to the catch block whose exception type matches the object thrown. The catch block handles the exception as appropriate. If the catch block ends normally, the flow of control passes over all subsequent catch blocks.

When an exception is not thrown from within a try block, the flow of control continues normally through the block, and passes over all catch blocks following the try block.

An exception handler cannot return control to the source of the error by using the return statement. A return issued in this context returns from the function containing the catch block.

If an exception is thrown and no try block is active, or if a try block is active and no catch block exception declaration matches the object thrown, a call to terminate() is issued. A call to terminate() in turn calls abort() to terminate the program. The abort() C library function is defined in the standard header file <stdlib.h>.



C++ Exception Handling Overview


Using a Conditional Expression in a Throw Expression
Example of Basic Exception Handling


Catching Exceptions
Nested Try Blocks
Rethrowing an Exception
Using Exception Handling
Exception Specifications
unexpected() and terminate() Functions