From 57a7528d135d51fae77ec0e2b2398c64f09d9b1e Mon Sep 17 00:00:00 2001
From: Martin Hierholzer <martin.hierholzer@desy.de>
Date: Wed, 28 Sep 2022 16:30:42 +0200
Subject: [PATCH] fix exceptions in constructor not shown properly

They were previously hidden by the "BUG found" message in
ApplicationBase due to the missing call to shutdown(). This is now being
called automatically in the Application destructor if the application
was not yet started fully, in which case this is ok to do there
(calling shutdown before destroying the Application data members is
important only if threads have been started already).
---
 include/Application.h |  2 ++
 src/Application.cc    | 10 ++++++++++
 2 files changed, 12 insertions(+)

diff --git a/include/Application.h b/include/Application.h
index 3dc31b8f..e324c0ac 100644
--- a/include/Application.h
+++ b/include/Application.h
@@ -49,6 +49,8 @@ namespace ChimeraTK {
      * characters. Use only alphanumeric characters and underscores. */
     explicit Application(const std::string& name);
 
+    ~Application() override;
+
     using ApplicationBase::getName;
 
     /** This will remove the global pointer to the instance and allows creating
diff --git a/src/Application.cc b/src/Application.cc
index 972a8059..5637bc02 100644
--- a/src/Application.cc
+++ b/src/Application.cc
@@ -46,6 +46,16 @@ Application::Application(const std::string& name) : ApplicationBase(name), Modul
 
 /*********************************************************************************************************************/
 
+Application::~Application() {
+  if(lifeCycleState == LifeCycleState::initialisation && !hasBeenShutdown) {
+    // likely an exception has been thrown in the initialisation phase, in which case we better call shutdown to prevent
+    // ApplicationBase from complaining and hiding the exception
+    ApplicationBase::shutdown();
+  }
+}
+
+/*********************************************************************************************************************/
+
 void Application::enableTestableMode() {
   assert(not initialiseCalled);
   testableMode.enable();
-- 
GitLab