Termination is likely the most sensible reaction when a program reaches an irrecoverable state, notably when invariants are violated.
The standard ways to terminate are std::abort (C) and std::terminate (C++).
Both approaches allow for custom handlers (albeit very limited in the case of std::abort).
std::abort: https://compiler-explorer.com/z/ThMhh3shr
std::terminate: https://compiler-explorer.com/z/6Yxb8187h
@simontoth
isn't the use of std::cerr a bit shady in terminate_handler.
it could be invoked from a throwing destructor of a global when cerr is already destroyed. or, otherwise corrupted.
i guess recursion wouldn't happen when a non-standard exception was thrown.
@PeterSommerlad Hmm, I guess technically, maybe. You would have to throw late enough during program termination.
I'm not quite sure what the wording is on doing something like that.