The default std::terminate_handler
calls std::abort
. std::terminate
is called in the case of an unhandled exception, or it can be called manually.
If I provide a terminate handler then it's only called if exceptions are enabled, but I don't see why this should be the case, and there's nothing in the documentation about it being disabled when exceptions are disabled. I don't see the connection between the terminate handler and exceptions, or why it's required. The terminate handler says "do this before aborting".
I don't know why it's disabled with exceptions disabled. Here is a question I asked earlier about this happening to me, and here is a reproducible example I made that shows that the terminate handler is no longer called when exceptions are disabled.
The above is the case on MSVC, and I don't know if it happens also with other compilers.
There is a question from 2018 that says:
std::terminate with disabled exceptions (MSVC implementation)
As it turns out, msvc has dummy implementation for terminate function when _HAS_EXCEPTIONS macro is not set:
inline void __CRTDECL terminate() _NOEXCEPT { // handle exception termination }
So it's just the case with MSVC, but is this still the case in 2025? That std::terminate
is just an empty function when exceptions are disabled?