summaryrefslogtreecommitdiffstats
path: root/src/main-lib/mainmacro.h
diff options
context:
space:
mode:
authorRobert Griebl <robert.griebl@qt.io>2024-03-06 15:32:08 +0100
committerRobert Griebl <robert.griebl@qt.io>2024-03-07 09:27:50 +0100
commit23b39347af03a40af4d19be9793f0f93a691a78f (patch)
treeedcb8693798a1eb4d45756cf74e7f34dfc10eae2 /src/main-lib/mainmacro.h
parentea49063b02733e3ec8caaf39a610fb70d24d5b0a (diff)
Fix exception handling after Q*Application::exec()
Uncaught exceptions thrown after we call exec() are originating from user code and we should not be catching those in our top-level catch handler. This will just print "ERROR: <what()>" without any context and make it look like the error is coming from the AM itself. Instead we need to run the event loop without a try/catch handler, so stray exception from user code go directly to our set_terminate handler in the CrashHandler class, which preserves as much context as possible and prints out a lot more useful meta data for debugging. Change-Id: Icc0432d5a6c5db85de439cafab89d05aa88b5891 Pick-to: 6.7 6.6 6.5 Reviewed-by: Dominik Holland <dominik.holland@qt.io>
Diffstat (limited to 'src/main-lib/mainmacro.h')
-rw-r--r--src/main-lib/mainmacro.h23
1 files changed, 13 insertions, 10 deletions
diff --git a/src/main-lib/mainmacro.h b/src/main-lib/mainmacro.h
index 2b99fcba..f27af6a6 100644
--- a/src/main-lib/mainmacro.h
+++ b/src/main-lib/mainmacro.h
@@ -14,21 +14,24 @@ QT_END_NAMESPACE_AM
#define QT_AM_MAIN() \
Q_DECL_EXPORT int main(int argc, char *argv[]) \
{ \
+ std::unique_ptr<QtAM::Main> a; \
+ std::unique_ptr<QtAM::Configuration> cfg; \
+\
try { \
- QtAM::Main a(argc, argv, QtAM::Main::InitFlag::ForkSudoServer | QtAM::Main::InitFlag::InitializeLogging); \
- \
- QtAM::Configuration cfg; \
- cfg.parseWithArguments(QCoreApplication::arguments()); \
- \
- a.setup(&cfg); \
- a.loadQml(cfg.loadDummyData()); \
- a.showWindow(cfg.fullscreen() && !cfg.noFullscreen()); \
- \
- return QtAM::MainBase::exec(); \
+ a = std::make_unique<QtAM::Main>(argc, argv, QtAM::Main::InitFlag::ForkSudoServer \
+ | QtAM::Main::InitFlag::InitializeLogging); \
+ cfg = std::make_unique<QtAM::Configuration>(); \
+ cfg->parseWithArguments(QCoreApplication::arguments()); \
+\
+ a->setup(cfg.get()); \
+ a->loadQml(); \
+ a->showWindow(cfg->fullscreen() && !cfg->noFullscreen()); \
} catch (const std::exception &e) { \
qCritical() << "ERROR:" << e.what(); \
return 2; \
} \
+\
+ return QtAM::Main::exec(); \
}
#endif // MAINMACRO_H