Catchable Types

Because C++ enables you to throw exceptions of any type, you need to determine which catch handlers can catch an exception of a specific class type. A C++ exception can be caught by a catch handler that specifies the same type as the thrown exception, or by a handler that can catch any type of exception. An exception can also be caught by a catch handler that uses a reference to the same type as the thrown exception.

If the type of thrown exception is a class, which also has a base class (or classes), it can be caught by handlers that accept base classes of the exception’s type, as well as references to bases of the exception’s type. Note that when an exception is caught by a reference, it is bound to the actual thrown exception object; otherwise, it is a copy (much the same as an argument to a function).

When an exception is thrown, it may be caught by the following types of catch handlers: