artdaq_core  v3_04_02
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 {
13  void ExceptionHandler(ExceptionHandlerRethrow decision, std::string optional_message)
14  {
15  if (optional_message != "")
16  {
17  TLOG(TLVL_ERROR) << optional_message;
18  }
19 
20  try
21  {
22  throw;
23  }
24  catch (const art::Exception& e)
25  {
26  TLOG(TLVL_ERROR) << "art::Exception object caught:" <<
27  " returnCode = " << e.returnCode() <<
28  ", categoryCode = " << e.categoryCode() <<
29  ", category = " << e.category();
30  TLOG(TLVL_ERROR) << "art::Exception object stream:" << e;
31 
32  if (decision == ExceptionHandlerRethrow::yes) { throw; }
33  }
34  catch (const cet::exception& e)
35  {
36  TLOG(TLVL_ERROR) << "cet::exception object caught:" <<
37  e.explain_self();
38 
39  if (decision == ExceptionHandlerRethrow::yes) { throw; }
40  }
41  catch (const boost::exception& e)
42  {
43  TLOG(TLVL_ERROR) << "boost::exception object caught: " <<
44  boost::diagnostic_information(e);
45 
46  if (decision == ExceptionHandlerRethrow::yes) { throw; }
47  }
48  catch (const std::exception& e)
49  {
50  TLOG(TLVL_ERROR) << "std::exception caught: " << e.what();
51 
52  if (decision == ExceptionHandlerRethrow::yes) { throw; }
53  }
54  catch (...)
55  {
56  TLOG(TLVL_ERROR) << "Exception of type unknown to artdaq::ExceptionHandler caught";
57 
58  if (decision == ExceptionHandlerRethrow::yes) { throw; }
59  }
60  }
61 }
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.