What is the behavior of a program if the handler indicated with set_terminate does not itself call abort()?
If I understand well, std::terminate() (in header exception) is called, e.g., when an exception is not caught. I read (also here) that std::terminate() is defined by default as a call to std::abort(), but can be modified using set_terminate(handler). What if the new handler doesn't call abort()? Is it added by default?
I illustrate below the behavior I don't understand. After a short message, the new handler for terminate() can either abort, or call terminate, or exit. If none of these options is set, the program ends with abnormal termination. But the same thing happens if abort() is inserted. If we use exit(), the program ends with a success and the error code written in exit(..). If we call terminate(), we get an endless loop (run fails, code 127).
This is with MinGW 6.3.0 on a Windows 8.1 computer, with NetBeans.
void myOwnOnExit() {
cerr << "called myOwnOnExit\n";
}
void myOwnTerminate() {
cerr << "called myOwnTerminate\n";
// Uncomment one of the following:
// // if none is uncommented, abnormal termination, error 3
// abort(); // with or without it, abnormal termination, error 3
// terminate(); // get an infinite loop, error code 127 in 3 seconds
// exit(EXIT_SUCCESS); // displays "called myOwnOnExit", success
}
int main() {
atexit(myOwnOnExit);
set_terminate(myOwnTerminate);
throw 1;
cerr << "we should not see this"; // and we don't
}
Thank you very much for any hint or suggestion.