Last active
July 27, 2017 11:26
-
-
Save odeblic/0ee40b2a3ae3a8151955198e8d217e0d to your computer and use it in GitHub Desktop.
Exception handling, enabled or not
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <exception> | |
#include <cstdlib> | |
void f() noexcept(false) | |
{ | |
std::cout << "f()" << std::endl; | |
throw('F'); | |
} | |
void g() noexcept(false) | |
{ | |
std::cout << "g()" << std::endl; | |
throw('G'); | |
try | |
{ | |
throw('G'); | |
} | |
catch(char) | |
{ | |
std::cout << "g::g()" << std::endl; | |
} | |
} | |
void h() | |
{ | |
std::cout << "h()" << std::endl; | |
throw('H'); | |
} | |
void myterminate() | |
{ | |
std::cout << "myterminate()" << std::endl; | |
abort(); | |
} | |
int main(int argc, char * argv[]) | |
{ | |
std::set_terminate(myterminate); | |
g(); | |
try | |
{ | |
g(); | |
} | |
catch(char e) | |
{ | |
std::cout << "exception of type 'char': " << e << std::endl; | |
} | |
catch(...) | |
{ | |
std::cout << "exception of unknown type" << std::endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment