std::unexpected_handler

From cppreference.com
 
 
 
Error handling
Exception handling
exception
uncaught_exception
exception_ptr (C++11)
make_exception_ptr (C++11)
current_exception (C++11)
rethrow_exception (C++11)
nested_exception (C++11)
throw_with_nested (C++11)
rethrow_if_nested (C++11)
Exception handling failures
terminate
terminate_handler
get_terminate (C++11)
set_terminate
unexpected (deprecated)
bad_exception
unexpected_handler (deprecated)
get_unexpected (C++11)(deprecated)
set_unexpected (deprecated)
Exception categories
logic_error
invalid_argument
domain_error
length_error
out_of_range
runtime_error
range_error
overflow_error
underflow_error
Error codes
Error codes
errno
Assertions
assert
system_error facility
error_category (C++11)
generic_category (C++11)
system_category (C++11)
error_condition (C++11)
errc (C++11)
error_code (C++11)
system_error (C++11)
 
Defined in header <exception>
typedef void (*unexpected_handler)();
(deprecated)

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_terminate), 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)
function called when dynamic exception specification is violated
(function)
(deprecated)
changes the function to be called by std::unexpected
(function)
(C++11)(deprecated)
obtains the current unexpected_handler
(function)