diff Framework/Messages/IObserver.h @ 977:262a0244e9b2 toa2019090201

Added missing Unregister for objects that register by the broker + logs + guard in FetchContext
author Benjamin Golinvaux <bgo@osimis.io>
date Mon, 02 Sep 2019 17:29:26 +0200
parents e75fd08d6c75
children 92a043b8e431
line wrap: on
line diff
--- a/Framework/Messages/IObserver.h	Sat Aug 31 13:50:11 2019 +0200
+++ b/Framework/Messages/IObserver.h	Mon Sep 02 17:29:26 2019 +0200
@@ -54,8 +54,33 @@
 
     virtual ~IObserver()
     {
-      LOG(TRACE) << "IObserver(" << std::hex << this << std::dec << ")::~IObserver : fingerprint_ == " << fingerprint_;
-      broker_.Unregister(*this);
+      try
+      {
+        LOG(TRACE) << "IObserver(" << std::hex << this << std::dec << ")::~IObserver : fingerprint_ == " << fingerprint_;
+        const char* deadMarker = "deadbeef-dead-dead-0000-0000deadbeef";
+        ORTHANC_ASSERT(strlen(deadMarker) == 36);
+        memcpy(fingerprint_, deadMarker, 37);
+        broker_.Unregister(*this);
+      }
+      catch (const Orthanc::OrthancException& e)
+      {
+        if (e.HasDetails())
+        {
+          LOG(ERROR) << "OrthancException in ~IObserver: " << e.What() << " Details: " << e.GetDetails();
+        }
+        else
+        {
+          LOG(ERROR) << "OrthancException in ~IObserver: " << e.What();
+        }
+      }
+      catch (const std::exception& e)
+      {
+        LOG(ERROR) << "std::exception in ~IObserver: " << e.what();
+      }
+      catch (...)
+      {
+        LOG(ERROR) << "Unknown exception in ~IObserver";
+      }
     }
 
     const char* GetFingerprint() const