mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-23 20:14:05 +00:00
feat: display exception name when unhandled exception got thrown
This commit is contained in:
parent
21fa719c03
commit
880bf4813b
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue