Last active
August 2, 2018 13:03
-
-
Save odeblic/f12f858588de08220aa6f9be22a01a45 to your computer and use it in GitHub Desktop.
Simultaneous exceptions
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> | |
struct bar | |
{ | |
~bar() | |
{ | |
std::cout << std::uncaught_exceptions() << " uncaught exceptions (bar 1)\n"; | |
try | |
{ | |
throw 'x'; | |
} | |
catch (char c) | |
{ | |
std::cout << std::uncaught_exceptions() << " uncaught exceptions (bar 2)\n"; | |
} | |
} | |
}; | |
struct foo | |
{ | |
~foo() | |
{ | |
std::cout << std::uncaught_exceptions() << " uncaught exceptions (foo 1)\n"; | |
try | |
{ | |
bar b; | |
throw 1; | |
} | |
catch (int i) | |
{ | |
std::cout << std::uncaught_exceptions() << " uncaught exceptions (foo 2)\n"; | |
} | |
} | |
}; | |
int main() | |
{ | |
std::cout << std::uncaught_exceptions() << " uncaught exceptions (main 1)\n"; | |
try | |
{ | |
foo f; | |
throw 1.1; | |
} | |
catch (double d) | |
{ | |
std::cout << std::uncaught_exceptions() << " uncaught exceptions (main 2)\n"; | |
} | |
std::cout << std::uncaught_exceptions() << " uncaught exceptions (main 3)\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment