diff options
| author | Christoph Berg <myon@debian.org> | 2020-11-16 21:55:31 +0100 |
|---|---|---|
| committer | Christoph Berg <myon@debian.org> | 2020-11-16 21:55:31 +0100 |
| commit | 62b7139bfe06fb6555de9a62ee3e62ccfd6e6cf1 (patch) | |
| tree | 3d9e4579a69060d2767ec2e9153b0ec60f78cb54 /ExceptionCatchingApplication.hpp | |
| parent | 8bf7a33f24073bbed51789cb9aaf36ef9126e543 (diff) | |
| parent | 77922fa33547ce24535f2e514c9a112dcb496f18 (diff) | |
Update upstream source from tag 'upstream/2.3.0_rc2+repack'
Update to upstream version '2.3.0~rc2+repack'
with Debian dir c40ed5d87e465612e7c15c7b67791946a5dcf64c
Diffstat (limited to 'ExceptionCatchingApplication.hpp')
| -rw-r--r-- | ExceptionCatchingApplication.hpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/ExceptionCatchingApplication.hpp b/ExceptionCatchingApplication.hpp new file mode 100644 index 00000000..8b23ab4d --- /dev/null +++ b/ExceptionCatchingApplication.hpp @@ -0,0 +1,45 @@ +#ifndef EXCEPTION_CATCHING_APPLICATION_HPP__ +#define EXCEPTION_CATCHING_APPLICATION_HPP__ + +#include <QApplication> + +#include "Logger.hpp" + +class QObject; +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. +// +class ExceptionCatchingApplication + : public QApplication +{ +public: + explicit ExceptionCatchingApplication (int& argc, char * * argv) + : QApplication {argc, argv} + { + } + bool notify (QObject * receiver, QEvent * e) override + { + try + { + return QApplication::notify (receiver, e); + } + catch (std::exception const& e) + { + LOG_FATAL (e.what ()); + throw; + } + catch (...) + { + LOG_FATAL ("Unexpected fatal error"); + throw; + } + } +}; + +#endif |
