std::unexpected_handler(3)
π NAME π
std::unexpected_handler β std::unexpected_handler
Hii bestie π
welcome to the std::unexpected_handler(3) page from the C++ Standard Libary. Yes, that's the whole name up there β we're keeping it iconic and exact. π
β¨ Synopsis β¨
Defined in header <exception>
typedef void (*unexpected_handler)(); (deprecated in C++11)
(removed in C++17)
Okay so quick vibe check: this type is deprecated in C++11 and removed in C++17, so if you meet it in the wild it's giving vintage-callback energy π
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. May, bestie β not "will" β read it again π
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:
- The exception thrown by
std::unexpected_handlersatisfies the dynamic exception specification that was violated earlier. The new exception is allowed to escape the function and stack unwinding continues. - The exception thrown by
std::unexpected_handlerstill violates the exception specification:- 2a) however, the exception specification allows
std::bad_exception: the thrown exception object is destroyed, andstd::bad_exceptionis constructed by the C++ runtime and thrown instead. - 2b) the exception specification does not allow
std::bad_exception:std::terminate()is called.
- 2a) however, the exception specification allows
π¨ No cap: those std::terminate() paths are real. If your handler lands in 2b, the program is done β periodt.
π See also π
unexpected(removed in C++17) β function called when dynamic exception specification is violated (function)set_unexpected(removed in C++17) β changes the function to be called bystd::unexpected(function)get_unexpected(C++11)(removed in C++17) β obtains the currentunexpected_handler(function)
Source/version/date sign-off, bestie:http://cppreference.comΒ·2024.06.10Β·std::unexpected_handler(3)β mwah π go forth and handle your unexpectedness responsibly π§
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms