From c74e115d2d099e3a0219a8965551c0e14523e87e Mon Sep 17 00:00:00 2001 From: Bill Somerville Date: Sat, 12 Jun 2021 02:46:55 +0100 Subject: [PATCH] Flush all logging sinks before aborting due to uncaught exceptions --- ExceptionCatchingApplication.hpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/ExceptionCatchingApplication.hpp b/ExceptionCatchingApplication.hpp index cfebc96fd..b9a3f9612 100644 --- a/ExceptionCatchingApplication.hpp +++ b/ExceptionCatchingApplication.hpp @@ -3,6 +3,7 @@ #include +#include #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; } };