Flush all logging sinks before aborting due to uncaught exceptions

This commit is contained in:
Bill Somerville 2021-06-12 02:46:55 +01:00
parent 87bca164f8
commit c74e115d2d
No known key found for this signature in database
GPG Key ID: D864B06D1E81618F
1 changed files with 7 additions and 4 deletions

View File

@ -3,6 +3,7 @@
#include <QApplication>
#include <boost/log/core.hpp>
#include "Logger.hpp"
class QObject;
@ -12,8 +13,8 @@ class QEvent;
// We can't use the GUI after QApplication::exit() is called so
// uncaught exceptions can get lost on Windows systems where there is
// no console terminal, so here we override QApplication::notify() and
// wrap the base class call with a try block to catch and display
// exceptions in a message box.
// wrap the base class call with a try block to catch and log any
// uncaught exceptions.
//
class ExceptionCatchingApplication
: public QApplication
@ -32,13 +33,15 @@ public:
catch (std::exception const& e)
{
LOG_FATAL ("Unexpected exception caught in event loop: " << e.what ());
qFatal ("Aborting");
}
catch (...)
{
LOG_FATAL ("Unexpected unknown exception caught in event loop");
qFatal ("Aborting");
}
// There's nowhere to go from here as Qt will not pass exceptions
// through the event loop, so we must abort.
boost::log::core::get ()->flush ();
qFatal ("Aborting");
return false;
}
};