00001 #include "ExceptionHandler.hh" 00002 00003 #include "canvas/Utilities/Exception.h" 00004 #include "cetlib/exception.h" 00005 #include "messagefacility/MessageLogger/MessageLogger.h" 00006 00007 #include <boost/exception/all.hpp> 00008 00009 namespace artdaq 00010 { 00011 void ExceptionHandler(ExceptionHandlerRethrow decision, std::string optional_message) 00012 { 00013 if (optional_message != "") 00014 { 00015 mf::LogError("ExceptionHandler") << optional_message; 00016 } 00017 00018 try 00019 { 00020 throw; 00021 } 00022 catch (const art::Exception& e) 00023 { 00024 mf::LogError("ExceptionHandler") << "art::Exception object caught:" << 00025 " returnCode = " << std::to_string(e.returnCode()) << 00026 ", categoryCode = " << e.categoryCode() << 00027 ", category = " << e.category(); 00028 mf::LogError("ExceptionHandler") << "art::Exception object stream:" << e; 00029 00030 if (decision == ExceptionHandlerRethrow::yes) { throw; } 00031 } 00032 catch (const cet::exception& e) 00033 { 00034 mf::LogError("ExceptionHandler") << "cet::exception object caught:" << 00035 e.explain_self(); 00036 00037 if (decision == ExceptionHandlerRethrow::yes) { throw; } 00038 } 00039 catch (const boost::exception& e) 00040 { 00041 mf::LogError("ExceptionHandler") << "boost::exception object caught: " << 00042 boost::diagnostic_information(e); 00043 00044 if (decision == ExceptionHandlerRethrow::yes) { throw; } 00045 } 00046 catch (const std::exception& e) 00047 { 00048 mf::LogError("ExceptionHandler") << "std::exception caught: " << e.what(); 00049 00050 if (decision == ExceptionHandlerRethrow::yes) { throw; } 00051 } 00052 catch (...) 00053 { 00054 mf::LogError("ExceptionHandler") << "Exception of type unknown to artdaq::ExceptionHandler caught"; 00055 00056 if (decision == ExceptionHandlerRethrow::yes) { throw; } 00057 } 00058 } 00059 }