Skip to content

Instantly share code, notes, and snippets.

@LB--
Created September 6, 2015 00:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LB--/113d4f6616d1a57470dc to your computer and use it in GitHub Desktop.
Save LB--/113d4f6616d1a57470dc to your computer and use it in GitHub Desktop.
C++ supports multiple active exceptions at once - see it in action at http://melpon.org/wandbox/permlink/PscHg988AnzjajyS
#include <iostream>
#include <stdexcept>
#include <exception>
struct ResonanceCascade final
{
ResonanceCascade()
{
std::cout << "ResonanceCascade ctor" << std::endl;
}
~ResonanceCascade() noexcept(false)
{
std::cout << "~ResonanceCascade() begin" << std::endl;
std::cout << "std::uncaught_exceptions() == " << std::uncaught_exceptions() << std::endl;
try
{
if(std::uncaught_exceptions() < 5)
{
ResonanceCascade rc;
throw std::logic_error{"Black Mesa"};
}
}
catch(...)
{
std::cout << "~ResonanceCascade() catch" << std::endl;
}
std::cout << "~ResonanceCascade() end" << std::endl;
}
};
int main()
{
try
{
ResonanceCascade rc;
throw std::logic_error{"Black Mesa"};
}
catch(...)
{
std::cout << "main catch" << std::endl;
}
}
@LB--
Copy link
Author

LB-- commented Sep 6, 2015

ResonanceCascade ctor
~ResonanceCascade() begin
std::uncaught_exceptions() == 1
ResonanceCascade ctor
~ResonanceCascade() begin
std::uncaught_exceptions() == 2
ResonanceCascade ctor
~ResonanceCascade() begin
std::uncaught_exceptions() == 3
ResonanceCascade ctor
~ResonanceCascade() begin
std::uncaught_exceptions() == 4
ResonanceCascade ctor
~ResonanceCascade() begin
std::uncaught_exceptions() == 5
~ResonanceCascade() end
~ResonanceCascade() catch
~ResonanceCascade() end
~ResonanceCascade() catch
~ResonanceCascade() end
~ResonanceCascade() catch
~ResonanceCascade() end
~ResonanceCascade() catch
~ResonanceCascade() end
main catch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment