c++ - Why is my terminate handler never invoked? -
i have read 1 can call std::set_terminate()
use own function global exception handler, catches unhandled exceptions.
simplified code of program:
#include <exception> #include <stdexcept> #include <iostream> void my_terminate_handler() { std::cerr << "terminate handler" << std::endl; std::cin.get(); std::abort(); } int main() { std::set_terminate(my_terminate_handler); int = 1; i--; std::cout << 1/i << std::endl; return 0; }
why my_terminate_handler()
never invoked? both in vc++ 2013, 2015 rc , gcc++-4.8.
the terminate handler called if program calls terminate
. can happen various reasons - including uncaught exception - division 0 isn't 1 of reasons. gives undefined behaviour; typically, raises signal (not c++ exception), , you'd need install signal handler, not terminate handler, catch that.
Comments
Post a Comment