artdaq_core  v3_05_07
ExceptionHandler.cc
1 
2 #define TRACE_NAME "ExceptionHandler"
3 #include "ExceptionHandler.hh"
4 
5 #include "canvas/Utilities/Exception.h"
6 #include "cetlib_except/exception.h"
7 #include "tracemf.h"
8 
9 #include <boost/exception/all.hpp>
10 
11 namespace artdaq {
12 void ExceptionHandler(ExceptionHandlerRethrow decision, std::string optional_message)
13 {
14  if (optional_message != "")
15  {
16  TLOG(TLVL_ERROR) << optional_message;
17  }
18 
19  try
20  {
21  throw;
22  }
23  catch (const art::Exception& e)
24  {
25  TLOG(TLVL_ERROR) << "art::Exception object caught:"
26  << " returnCode = " << e.returnCode() << ", categoryCode = " << e.categoryCode() << ", category = " << e.category();
27  TLOG(TLVL_ERROR) << "art::Exception object stream:" << e;
28 
29  if (decision == ExceptionHandlerRethrow::yes) { throw; }
30  }
31  catch (const cet::exception& e)
32  {
33  TLOG(TLVL_ERROR) << "cet::exception object caught:" << e.explain_self();
34 
35  if (decision == ExceptionHandlerRethrow::yes) { throw; }
36  }
37  catch (const boost::exception& e)
38  {
39  TLOG(TLVL_ERROR) << "boost::exception object caught: " << boost::diagnostic_information(e);
40 
41  if (decision == ExceptionHandlerRethrow::yes) { throw; }
42  }
43  catch (const std::exception& e)
44  {
45  TLOG(TLVL_ERROR) << "std::exception caught: " << e.what();
46 
47  if (decision == ExceptionHandlerRethrow::yes) { throw; }
48  }
49  catch (...)
50  {
51  TLOG(TLVL_ERROR) << "Exception of type unknown to artdaq::ExceptionHandler caught";
52 
53  if (decision == ExceptionHandlerRethrow::yes) { throw; }
54  }
55 }
56 } // namespace artdaq
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.