std::unexpected_handler(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸ’– 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:

  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.
🚨 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 by std::unexpected (function)
  • get_unexpected (C++11)(removed in C++17) β€” obtains the current unexpected_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