unexpected() — Handle exception not listed in exception specification
Standards
Standards / Extensions | C or C++ | Dependencies |
---|---|---|
ANSI/ISO
C++ |
C++ only |
Format
#include <exception>
void unexpected(void);
General description
void f() throw() // function may throw no exceptions
{throw "bad"; } // throw calls unexpected()
the
unexpected_handler is the one in effect immediately after evaluating
the throw expression.- Throwing an object of a type listed in the exception specification (or an object of any type if the unexpected handler is called directly by the program).
- Throwing an object of type bad_exception.
- Calling terminate(), abort(), or exit(int).
In a multithreaded environment, if a thread throws an exception that is not listed in its exception specification, then unexpected() is called. The default for unexpected() is to call terminate(), which defaults to calling abort(), which then causes a SIGABRT signal to be generated to the thread issuing the throw. If the SIGABRT signal is not caught, the process is terminated. You can replace the default unexpected() behavior for all threads in the process by using the set_unexpected() function. One possible use of set_unexpected() is to call a function which issues a pthread_exit(). If this is done, a throw of a condition by a thread that is not in the exception specification results in thread termination, but not process termination.
Returned value
unexpected() returns no values.
Refer to z/OS XL C/C++ Language Reference for more information about z/OS XL C++ exception handling, including the unexpected() function.