/**
* Helper function to retrieve TLS pointer.
* Initializes the pointer if called for the first time.
- * @return Pointer to the per thread container
+ * @return Pointer to the per thread container or NULL if error occurs
*/
-static PerThreadContainer *TLS_get_container()
+static PerThreadContainer *TLS_get_container() throw ()
{
// First call? Construct options container
if (thread_container.get() == NULL)
- thread_container.reset(new PerThreadContainer());
+ {
+ try
+ {
+ thread_container.reset(new PerThreadContainer());
+ }
+ catch (...)
+ {
+ return NULL;
+ }
+ }
PerThreadContainer *per_thread = thread_container.get();
}
} // eo ensure_indent_level(int)
+/**
+ * @brief try logging that some problem occurred
+ *
+ * Keep in mind that problem could be with the logger itself, so wrap all this
+ * in a try-catch agin
+ */
+ static void try_logging_error(const std::string &message) throw ()
+{
+ try
+ {
+ GlobalLogger.debug() << "Problem occurred in ScopeTracker: " << message;
+ }
+ catch (...)
+ { // nothing more we can do
+ }
+}
+
+
} // eo namespace <anonymous>
, FuncDepth(0)
, PerThread(TLS_get_container())
{
+ if (PerThread == NULL)
+ {
+ try_logging_error("Failed to get thread local storage");
+ return;
+ }
if (!PerThread->scope_tracker_list.empty())
{
ScopeTracker* last_tracker= PerThread->scope_tracker_list.back();
*/
ScopeTracker::~ScopeTracker()
{
+ if (PerThread == NULL)
+ {
+ try_logging_error("Failed to get thread local storage");
+ return;
+ }
// spit a message
if (Logger::has_log_level(Logger::LogLevel::Debug))
{