]> git.sesse.net Git - casparcg/blobdiff - common/concurrency/com_context.h
2.0. stage: Changed error handling.
[casparcg] / common / concurrency / com_context.h
index 31ab5a1623b8845dc37a937aca256d6384b7865e..b3b985ddfc99ae28d415aeac9e8b88f433432511 100644 (file)
@@ -3,6 +3,7 @@
 #include "executor.h"\r
 \r
 #include "../log/log.h"\r
+#include "../exception/exceptions.h"\r
 \r
 #define NOMINMAX\r
 #define WIN32_LEAN_AND_MEAN\r
@@ -37,7 +38,7 @@ public:
                        ::CoUninitialize();\r
                }).timed_wait(boost::posix_time::milliseconds(500)))\r
                {\r
-                       CASPAR_LOG(error) << L"[com_contex] Timer expired, deadlock detected and released, leaking resources";\r
+                       CASPAR_LOG(error) << L"[com_contex] Timer expired, deadlock detected and released, leaking resources.";\r
                }\r
        }\r
        \r
@@ -51,11 +52,25 @@ public:
                });\r
        }\r
 \r
-       T& operator*() const { return *instance_.get();}  // noexcept\r
+       T& operator*() const \r
+       {\r
+               if(instance_ == nullptr)\r
+                       BOOST_THROW_EXCEPTION(invalid_operation() << msg_info("Tried to access null context."));\r
+\r
+               return *instance_.get();\r
+       }  // noexcept\r
 \r
-       T* operator->() const { return instance_.get();}  // noexcept\r
+       T* operator->() const \r
+       {\r
+               if(instance_ == nullptr)\r
+                       BOOST_THROW_EXCEPTION(invalid_operation() << msg_info("Tried to access null context."));\r
+               return instance_.get();\r
+       }  // noexcept\r
 \r
-       T* get() const { return instance_.get();}  // noexcept\r
+       T* get() const\r
+       {\r
+               return instance_.get();\r
+       }  // noexcept\r
 \r
        operator bool() const {return get() != nullptr;}\r
 };\r