artdaq_core  v3_01_04
ExceptionHandler.cc
1 #include "ExceptionHandler.hh"
2 
3 #include "canvas/Utilities/Exception.h"
4 #include "cetlib/exception.h"
5 #include "tracemf.h"
6 
7 #include <boost/exception/all.hpp>
8 
9 #undef TRACE_NAME
10 #define TRACE_NAME "ExceptionHandler"
11 
12 namespace artdaq
13 {
14  void ExceptionHandler(ExceptionHandlerRethrow decision, std::string optional_message)
15  {
16  if (optional_message != "")
17  {
18  TLOG(TLVL_ERROR) << optional_message;
19  }
20 
21  try
22  {
23  throw;
24  }
25  catch (const art::Exception& e)
26  {
27  TLOG(TLVL_ERROR) << "art::Exception object caught:" <<
28  " returnCode = " << std::to_string(e.returnCode()) <<
29  ", categoryCode = " << e.categoryCode() <<
30  ", category = " << e.category();
31  TLOG(TLVL_ERROR) << "art::Exception object stream:" << e;
32 
33  if (decision == ExceptionHandlerRethrow::yes) { throw; }
34  }
35  catch (const cet::exception& e)
36  {
37  TLOG(TLVL_ERROR) << "cet::exception object caught:" <<
38  e.explain_self();
39 
40  if (decision == ExceptionHandlerRethrow::yes) { throw; }
41  }
42  catch (const boost::exception& e)
43  {
44  TLOG(TLVL_ERROR) << "boost::exception object caught: " <<
45  boost::diagnostic_information(e);
46 
47  if (decision == ExceptionHandlerRethrow::yes) { throw; }
48  }
49  catch (const std::exception& e)
50  {
51  TLOG(TLVL_ERROR) << "std::exception caught: " << e.what();
52 
53  if (decision == ExceptionHandlerRethrow::yes) { throw; }
54  }
55  catch (...)
56  {
57  TLOG(TLVL_ERROR) << "Exception of type unknown to artdaq::ExceptionHandler caught";
58 
59  if (decision == ExceptionHandlerRethrow::yes) { throw; }
60  }
61  }
62 }
ExceptionHandlerRethrow
Controls whether the ExceptionHandler will rethrow after printing exception details.
Rethrow the exception after sending details to MessageFacility.
void ExceptionHandler(ExceptionHandlerRethrow decision, std::string optional_message)
The ExceptionHandler class prints out all available information about an excection, then optionally re-throws.