I have the following terminate handler:
void on_terminate()
{
std::exception_ptr eptr = std::current_exception();
if (eptr)
{
try
{
std::rethrow_exception(eptr);
}
catch (const std::exception& e)
{
DBG_FAIL(e.what());
}
catch (...)
{
DBG_FAIL("Unknown exception.");
}
}
else
{
DBG_FAIL("Terminate was called.");
}
}
I have been using this handler for a while now and I strongly believe that it worked. But recently it appears that when an exception is throw unhanded I still end up at "Terminate was called."
. (I still get a useful call stack.)
I am experiencing the issue on VS2015 Up3 and did not yet have time to check other compilers and platforms. (GCC on Cygwin does not implement exception_ptr yet.) Am I doing something fundamentally wrong?
Given the following code:
int main(int argc, char* argv[])
{
std::set_terminate(on_terminate);
throw std::runtime_error("#yolo");
}
You can test the issue.
For completeness here you can find my dbg.h.