hachyderm.io is one of the many independent Mastodon servers you can use to participate in the fediverse.
Hachyderm is a safe space, LGBTQIA+ and BLM, primarily comprised of tech industry professionals world wide. Note that many non-user account types have restrictions - please see our About page.

Administered by:

Server stats:

9.5K
active users

Šimon Tóth

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: compiler-explorer.com/z/ThMhh3
std::terminate: compiler-explorer.com/z/6Yxb81

@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.