std::terminate

From cppreference.com
< cpp‎ | error
Defined in header <exception>
void terminate();
(until C++11)
[ [noreturn] ] void terminate( ) noexcept ;
(since C++11)

std::terminate() is called by the C++ runtime when the program cannot continue for any of the following reasons:

1) An exception is thrown and not caught (it is implementation-defined whether any stack unwinding is done in this case).
2)
3) The constructor or the destructor of a static or thread-local(since C++11)
4) A function registered with std::atexit or std::at_quick_exit (since C++11)
5) A dynamic exception specification is violated and the default handler for std::unexpected
6) A non-default handler for std::unexpected throws an exception that violates the previously violated dynamic exception specification, if the specification does not include std::bad_exception
(until C++17)
9) An exception is thrown from the initial function of std::thread.
10) A joinable std::thread is destroyed or assigned to.
(since C++11)
12) A function invoked by a parallel algorithm exits via an uncaught exception and the execution policy
(since C++17)

std::terminate() may also be called directly from the program.

When std::terminate is called due to a thrown exception, an implicit try/catch handler is considered active. Thus, calling std::current_exception

In any case, std::terminate calls the currently installed std::terminate_handler. The default std::terminate_handler calls std::abort

If a destructor reset the terminate handler during stack unwinding and the unwinding later led to terminate

(until C++11)

If a destructor reset the terminate handler during stack unwinding, it is unspecified which handler is called if the unwinding later led to terminate being called.

(since C++11)

Notes

If the handler mechanism is not wanted, e.g. because it requires atomic operations which may bloat binary size, a direct call to std::abort

Some compiler intrinsics, e.g. __builtin_trap (gcc, clang, and icc) or __debugbreak

Defect reports

The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

DR Applied to Behavior as published Correct behavior
LWG 2111 C++11 effect of calling std::set_terminate during stack
unwinding differs from C++98 and breaks some ABIs
made unspecified

See also

the type of the function called by std::terminate
(typedef)
causes abnormal program termination (without cleaning up)
(function)
(C++26)
pauses the running program when called
(function)