According to the requirments of the standard, a function used as a terminate_handler
must meet the following requirement (ISO/IEC 14882:2011 18.8.3.1):
Required behavior: A terminate_handler
shall terminate execution of the program without returning
to the caller.
As your function doesn't meet this requirement you program has undefined behaviour. In order to see your custom diagnostic you should output a newline to std::cout
(as this can be required on many platforms) and then terminate the program in some way, such as calling std::abort
.
std::abort
is used to signal an abnormal termination of the program so you can expect extra diagnostics to be reported to the user such as via the dialog box that you are seeing.
Note that using std::exit
from a terminate handler is potentially dangerous as std::terminate
might be called in response to an exceptional condition occurring in a function registered with std::atexit
or std:: at_quick_exit
. This would lead to a second attempt to call std::exit
.
In summary, if you don't want an "abnormal" termination, you almost always need to catch exceptions that you throw.