feat: display exception name when unhandled exception got thrown

This commit is contained in:
shenleban tongying 2023-04-10 00:36:07 -04:00 committed by xiaoyifang
parent 21fa719c03
commit 880bf4813b

View file

@ -9,8 +9,26 @@
static void termHandler()
{
QString message( "GoldenDict has crashed with an unexpected exception\n\n" );
qDebug() << message;
// Trick: In c++17, there is no standardized way to know the exception name/type inside terminate_handler
// So, we just get the exception and throw it again, so that we can call the std::exception::what :)
// This trick can be removed/improved if something similar to
// boost::current_exception_diagnostic_information got standardized,
std::exception_ptr curException = std::current_exception();
try {
if ( curException != nullptr ) {
std::rethrow_exception( curException );
}
else {
qDebug() << "GoldenDict has crashed unexpectedly.\n\n";
}
}
catch ( const std::exception & e ) {
qDebug() << "GoldenDict has crashed with exception: " << e.what() ;
}
if( logFilePtr && logFilePtr->isOpen() )
logFilePtr->close();