$treeview $search $mathjax $extrastylesheet
artdaq_core
v3_06_01
$projectbrief
|
$projectbrief
|
$searchbox |
00001 00002 #define TRACE_NAME "ExceptionHandler" 00003 #include "ExceptionHandler.hh" 00004 #include "ExceptionStackTrace.hh" 00005 00006 #include "canvas/Utilities/Exception.h" 00007 #include "cetlib_except/exception.h" 00008 #include "tracemf.h" 00009 00010 #include <boost/exception/all.hpp> 00011 namespace artdaq { 00012 00013 #ifdef EXCEPTIONSTACKTRACE 00014 inline void PrintExceptionStackTrace() 00015 { 00016 auto message = artdaq::debug::getStackTraceCollector().print_stacktrace(); 00017 00018 std::string::size_type pos = 0; 00019 std::string::size_type prev = 0; 00020 00021 while ((pos = message.find('\n', prev)) != std::string::npos) 00022 { 00023 TLOG(TLVL_DEBUG) << message.substr(prev, pos - prev); 00024 prev = pos + 1; 00025 } 00026 00027 TLOG(TLVL_DEBUG) << message.substr(prev); 00028 } 00029 #else 00030 inline void PrintExceptionStackTrace() 00031 {} 00032 #endif 00033 00034 void ExceptionHandler(ExceptionHandlerRethrow decision, const std::string& optional_message) 00035 { 00036 if (!optional_message.empty()) 00037 { 00038 TLOG(TLVL_ERROR) << optional_message; 00039 } 00040 00041 try 00042 { 00043 throw; 00044 } 00045 catch (const art::Exception& e) 00046 { 00047 TLOG(TLVL_ERROR) << "art::Exception object caught:" 00048 << " returnCode = " << e.returnCode() << ", categoryCode = " << e.categoryCode() << ", category = " << e.category(); 00049 TLOG(TLVL_ERROR) << "art::Exception object stream:" << e; 00050 PrintExceptionStackTrace(); 00051 00052 if (decision == ExceptionHandlerRethrow::yes) { throw; } 00053 } 00054 catch (const cet::exception& e) 00055 { 00056 TLOG(TLVL_ERROR) << "cet::exception object caught:" << e.explain_self(); 00057 PrintExceptionStackTrace(); 00058 00059 if (decision == ExceptionHandlerRethrow::yes) { throw; } 00060 } 00061 catch (const boost::exception& e) 00062 { 00063 TLOG(TLVL_ERROR) << "boost::exception object caught: " << boost::diagnostic_information(e); 00064 PrintExceptionStackTrace(); 00065 00066 if (decision == ExceptionHandlerRethrow::yes) { throw; } 00067 } 00068 catch (const std::exception& e) 00069 { 00070 TLOG(TLVL_ERROR) << "std::exception caught: " << e.what(); 00071 PrintExceptionStackTrace(); 00072 00073 if (decision == ExceptionHandlerRethrow::yes) { throw; } 00074 } 00075 catch (...) 00076 { 00077 TLOG(TLVL_ERROR) << "Exception of type unknown to artdaq::ExceptionHandler caught"; 00078 PrintExceptionStackTrace(); 00079 00080 if (decision == ExceptionHandlerRethrow::yes) { throw; } 00081 } 00082 } 00083 } // namespace artdaq