Name
unexpected function — Handles an unexpected exception type
Synopsis
void unexpected( )
If a function has an exception specification and throws an
exception that is not listed in the exception specification, the
unexpected
function is called to
handle the unexpected exception.
You can implement your own unexpected
function. If you do so, you
must ensure that unexpected
does
not return normally. It can terminate the program—for example, by
calling terminate
—or it can throw
an exception.
If your unexpected
function
throws an exception that is not listed in the function’s exception
specification, a new exception of type bad_exception
is created and thrown. If
the function’s exception specification does not list bad_exception
, terminate
is called automatically.
The default implementation of unexpected
calls terminate
.
In other words, if a function has an exception specification, it is guaranteed that only the specified exceptions can be thrown out of the function, or else the application will be terminated.
See Also
bad_exception class,
set_unexpected function,
abort
in <cstdlib>
, throw
keyword
Get C++ In a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.