The C++ language provides a facility for restricting the type of exceptions
that may be thrown by a function. The declaration
of a function may include a list of the types of exceptions that may be
thrown (directly or indirectly) by the function. The syntax of such lists is shown below.
A simple example of an exception specification list is shown below.
void f() throws(exceptionA,exceptionB,exceptionC)
The following is true of exception specifications.
- The exception specification determines that the function f can throw any of
the three exception types exceptionA, exceptionB and exceptionC. The following applies to
- An attempt by a function to throw an exception not contained in its exception
specification list causes a call to the function
- Violations of exception specifications are handled by the exception runtime component.
- A C++ compiler may not reject an expression merely because it may possibly throw
an exception not listed in the containing function's exception specification list.
- A function that does not possess an exception specification list may throw any exception.
- A function that has an empty exception specification list may not throw any exceptions.
- A function that is permitted to throw an exception of a certain class is also
permitted to throw any class publicly deriving from that class.
- An exception specification for a function is not regarded as being part of
that function's type.