Skip to content

Instantly share code, notes, and snippets.

@odeblic
Last active August 2, 2018 13:03
Show Gist options
  • Save odeblic/f12f858588de08220aa6f9be22a01a45 to your computer and use it in GitHub Desktop.
Save odeblic/f12f858588de08220aa6f9be22a01a45 to your computer and use it in GitHub Desktop.
Simultaneous exceptions
#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