Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // exception_set_terminate.cpp
- // compile with: /EHsc
- //http://www.argc-argv.com/5_****/article01.pdf
- #include "stdafx.h"
- #include <exception>
- #include <iostream>
- using namespace std;
- void termfunction()
- {
- cout << "My terminate function called." << endl;
- abort();
- exit(EXIT_FAILURE);
- }
- void uefunction()
- {
- cout << "My unhandled exception function called." << endl;
- terminate(); // this is what unexpected() calls by default
- }
- void func(){
- int x = 1;
- throw bad_alloc();
- cout << x / (++x - 2) << endl;
- //terminate();
- }
- int main()
- {
- terminate_handler oldHandler1 = set_terminate(termfunction);
- unexpected_handler oldHandler2 = set_unexpected(uefunction);
- // Throwing an unhandled exception would also terminate the program
- // or we could explicitly call terminate();
- func();
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement