Skip to content

Instantly share code, notes, and snippets.

@tfc
Created March 18, 2016 09:55
Show Gist options
  • Save tfc/295bed5e08ae1c75e7c0 to your computer and use it in GitHub Desktop.
Save tfc/295bed5e08ae1c75e7c0 to your computer and use it in GitHub Desktop.
How uncaught exceptions are resolved
#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