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