debug: print more extensive errors during abort_with_trace

This commit is contained in:
Danny Robson 2018-09-14 13:50:14 +10:00
parent e15f687e20
commit cffc3bbc46

View File

@ -70,7 +70,23 @@ warn (const char *msg)
////////////////////////////////////////////////////////////////////////////////
static void abort_with_trace (void)
{
LOG_EMERGENCY ("aborting: %!", debug::backtrace {});
// If this is because of an exception we may as well rethrow and hope that
// the system will print exception data during the abort process.
//
// But we can at least try to print anything derived from std::exception
// (which is a likely guess) before we self-destruct.
if (auto ptr = std::current_exception (); ptr) {
try {
std::rethrow_exception (ptr);
} catch (std::exception const &x) {
LOG_EMERGENCY ("unhandled exception: %!\n%!", x.what (), debug::backtrace {});
} catch (...) {
LOG_EMERGENCY ("unhandled exception: %!\n", debug::backtrace {});
}
} else {
LOG_EMERGENCY ("aborting: %!", debug::backtrace {});
}
std::abort ();
}