Created
March 18, 2016 09:55
-
-
Save tfc/295bed5e08ae1c75e7c0 to your computer and use it in GitHub Desktop.
How uncaught exceptions are resolved
This file contains 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 <string> | |
class Foo | |
{ | |
const std::string str; | |
public: | |
Foo(const std::string &str_) : str{str_} {} | |
~Foo() { std::cout << str << " Foo's dtor called." << std::endl; } | |
}; | |
Foo gfoo {"global"}; | |
static Foo sgfoo {"static global"}; | |
int main() | |
{ | |
try { | |
Foo lfoo {"local stack"}; | |
throw int(123); | |
} catch (char) { // Change to int in order to catch the exception | |
std::cout << "Exception catched." << std::endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment