I want to use my own functions instead of the default unexpected() and terminate() Could any one give me a short example on how to declare set_unexpected and set_terminate in main for this? I can't seem to get it to work. Thanks
I want to use my own functions instead of the default unexpected() and terminate() Could any one give me a short example on how to declare set_unexpected and set_terminate in main for this? I can't seem to get it to work. Thanks
Something like -
Code:#include <iostream> #include <exception> using namespace std; void my_terminate() { cout << "my terminate"; cin.get(); exit(0); } void fn() { throw; } int main() { set_terminate(my_terminate); fn(); return 0; }
thanks, what about set_unexpected though? I want it to go through my unexpected function when I throw an unexpected object then my_unexpected calls my_terminate.
This works on Dev C++ (mingw) -
Code:#include <iostream> #include <exception> using namespace std; void my_unexpected() { cout << "my unexpected"; throw; } void my_terminate() { cout << "my terminate"; cin.get(); exit(0); } void fn()throw() { throw unexpected; } int main() { set_unexpected(my_unexpected); set_terminate(my_terminate); fn(); return 0; }
hmmm, I was doing something very similar, but for some reason when I throw an unexpected object it just goes straight to terminate() and not to unexpected(). I'm running my programs in UNIX
Thanks, anyway