std::unexpected_handler

From cppreference.com
< cpp‎ | error
 
 
Utilities library
Type support (basic types, RTTI, type traits)
Dynamic memory management
Error handling
Program utilities
Variadic functions
Date and time
Function objects
(C++11)
Relational operators
Optional and any
(C++17)
(C++17)
Pairs and tuples
(C++11)
(C++17)
Swap, forward and move
(C++14)
(C++11)
(C++11)
Type operations
(C++11)
(C++17)
 
Error handling
Exception handling
(C++11)
(C++17)
Exception handling failures
(C++11)
(deprecated)
unexpected_handler
(deprecated)
(C++11)(deprecated)
(deprecated)
 
Defined in header <exception>
typedef void (*unexpected_handler)();
(deprecated since C++11)

std::unexpected_handler is the function pointer type (pointer to function that takes no arguments and returns void), which is installed and queried by the functions std::set_unexpected and std::get_unexpected and called by std::unexpected.

The C++ implementation provides a default std::unexpected_handler function, which calls std::terminate(). If the null pointer value is installed (by means of std::set_unexpected), the implementation may restore the default handler instead.

A user-defined std::unexpected_handler is expected to either terminate the program or throw an exception. If it throws an exception, one of the following three situations may be encountered:

1) the exception thrown by std::unexpected_handler satisfies the dynamic exception specification that was violated earlier. The new exception is allowed to escape the function and stack unwinding continues.

2) the exception thrown by std::unexpected_handler still violates the exception specification:

2a) however, the exception specification allows std::bad_exception: the thrown exception object is destroyed, and std::bad_exception is constructed by the C++ runtime and thrown instead.

2b) the exception specification does not allow std::bad_exception: std::terminate() is called.

[edit] See also

(deprecated since C++11)
function called when dynamic exception specification is violated
(function)
(deprecated since C++11)
changes the function to be called by std::unexpected
(function)
(C++11)(deprecated)
obtains the current unexpected_handler
(function)