libmoost
/home/mhx/git/github/libmoost/include/moost/thread/detail/safe_thread_default_policy.hpp
Go to the documentation of this file.
00001 /* vim:set ts=3 sw=3 sts=3 et: */
00028 #ifndef MOOST_THREAD_SAFE_THREAD_GROUP_DEFAULT_POLICY
00029 #define MOOST_THREAD_SAFE_THREAD_GROUP_DEFAULT_POLICY
00030 
00031 #include <stdexcept>
00032 
00033 #include "../../logging.hpp"
00034 
00035 namespace moost { namespace thread {
00036 
00037    struct default_safe_thread_policy
00038    {
00039       template<typename F>
00040       void operator()(F & f) const
00041       {
00042          try
00043          {
00044             f();
00045          }
00046          catch(boost::thread_interrupted const &)
00047          {
00048             throw; // rethrow this as it means the thread was intentionally interupted
00049          }
00050          catch(std::exception const & e)
00051          {
00052             // Log and ignore (the thread will be terminated but the process lives on!)
00053             MLOG_NAMED_ERROR("Unhandled Thread Exception", e.what());
00054          }
00055          catch(...)
00056          {
00057             // Log and ignore (the thread will be terminated but the process lives on!)
00058             MLOG_NAMED_ERROR("Unhandled Thread Exception", "Unknown Error");
00059          }
00060       }
00061    };
00062 }}
00063 
00064 #endif