2 #define TRACE_NAME "ExceptionHandler"
3 #include "ExceptionHandler.hh"
4 #include "ExceptionStackTrace.hh"
6 #include "canvas/Utilities/Exception.h"
7 #include "cetlib_except/exception.h"
10 #include <boost/exception/all.hpp>
13 #ifdef EXCEPTIONSTACKTRACE
14 inline void PrintExceptionStackTrace()
18 std::string::size_type pos = 0;
19 std::string::size_type prev = 0;
21 while ((pos = message.find(
'\n', prev)) != std::string::npos)
23 TLOG(TLVL_DEBUG) << message.substr(prev, pos - prev);
27 TLOG(TLVL_DEBUG) << message.substr(prev);
30 inline void PrintExceptionStackTrace()
36 if (!optional_message.empty())
38 TLOG(TLVL_ERROR) << optional_message;
45 catch (
const art::Exception& e)
47 TLOG(TLVL_ERROR) <<
"art::Exception object caught:"
48 <<
" returnCode = " << e.returnCode() <<
", categoryCode = " << e.categoryCode() <<
", category = " << e.category();
49 TLOG(TLVL_ERROR) <<
"art::Exception object stream:" << e;
50 PrintExceptionStackTrace();
54 catch (
const cet::exception& e)
56 TLOG(TLVL_ERROR) <<
"cet::exception object caught:" << e.explain_self();
57 PrintExceptionStackTrace();
61 catch (
const boost::exception& e)
63 TLOG(TLVL_ERROR) <<
"boost::exception object caught: " << boost::diagnostic_information(e);
64 PrintExceptionStackTrace();
68 catch (
const std::exception& e)
70 TLOG(TLVL_ERROR) <<
"std::exception caught: " << e.what();
71 PrintExceptionStackTrace();
77 TLOG(TLVL_ERROR) <<
"Exception of type unknown to artdaq::ExceptionHandler caught";
78 PrintExceptionStackTrace();
ExceptionHandlerRethrow
Controls whether the ExceptionHandler will rethrow after printing exception details.
Rethrow the exception after sending details to MessageFacility.
void ExceptionHandler(ExceptionHandlerRethrow decision, const std::string &optional_message)
The ExceptionHandler class prints out all available information about an excection, then optionally re-throws.
std::string print_stacktrace()
Produces a stack trace summary.