LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
OptionsHandler.cc
Go to the documentation of this file.
2 
3 #include "cetlib_except/demangle.h"
4 #include "cetlib_except/exception.h"
5 
6 #include <exception>
7 #include <iostream>
8 #include <typeinfo>
9 
10 namespace {
11 
12  // class F must be callable with no arguments, and return 'int'.
13  template <class F>
14  int
15  exceptionCatcher(F func, std::string const& funcName, int failureCode)
16  {
17  try {
18  return func();
19  }
20  catch (cet::exception& e) {
21  std::cerr << "OptionsHandler caught a cet::exception calling " << funcName
22  << '\n'
23  << e.what() << '\n';
24  }
25  catch (std::exception& e) {
26  std::cerr << "OptionsHandler caught an std::exception calling "
27  << funcName << '\n'
28  << e.what() << '\n';
29  }
30  catch (std::string& s) {
31  std::cerr << "OptionsHandler caught a string exception calling "
32  << funcName << '\n'
33  << s << '\n';
34  }
35  catch (char const* s) {
36  std::cerr << "OptionsHandler caught a string exception calling "
37  << funcName << '\n'
38  << s << '\n';
39  }
40  catch (...) {
41  std::cerr << "OptionsHandler caught an unknown exception calling "
42  << funcName << '\n';
43  }
44  return failureCode;
45  }
46 } // namespace
47 
49 
50 int
51 art::OptionsHandler::checkOptions(bpo::variables_map const& vm)
52 {
53  std::string const thisClass(cet::demangle_symbol(typeid(*this).name()));
54  return exceptionCatcher([&vm, this] { return doCheckOptions(vm); },
55  thisClass + "::doCheckOptions()",
56  89);
57 }
58 
59 int
60 art::OptionsHandler::processOptions(bpo::variables_map const& vm,
61  fhicl::intermediate_table& raw_config)
62 {
63  std::string const thisClass(cet::demangle_symbol(typeid(*this).name()));
64  return exceptionCatcher(
65  [&, this] { return doProcessOptions(vm, raw_config); },
66  thisClass + "::doProcessOptions()",
67  90);
68 }
virtual ~OptionsHandler()
int processOptions(bpo::variables_map const &vm, fhicl::intermediate_table &raw_config)
virtual int doCheckOptions(bpo::variables_map const &vm)=0
int checkOptions(bpo::variables_map const &vm)
Float_t e
Definition: plot.C:35
virtual int doProcessOptions(bpo::variables_map const &vm, fhicl::intermediate_table &raw_config)=0
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33