diff --git a/termination.cc b/termination.cc index 3ace17a6..ee165e2c 100644 --- a/termination.cc +++ b/termination.cc @@ -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();