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,
16  std::string const& funcName [[maybe_unused]],
17  int failureCode)
18  {
19  try {
20  return func();
21  }
22  catch (cet::exception& e) {
23  std::cerr << "OptionsHandler caught a cet::exception calling " << funcName
24  << "\n"
25  << e.what() << "\n";
26  }
27  catch (std::exception& e) {
28  std::cerr << "OptionsHandler caught an std::exception calling "
29  << funcName << "\n"
30  << e.what() << "\n";
31  }
32  catch (std::string& s) {
33  std::cerr << "OptionsHandler caught a string exception calling "
34  << funcName << "\n"
35  << s << "\n";
36  }
37  catch (char const* s) {
38  std::cerr << "OptionsHandler caught a string exception calling "
39  << funcName << "\n"
40  << s << "\n";
41  }
42  catch (...) {
43  std::cerr << "OptionsHandler caught an unknown exception calling "
44  << funcName << "\n";
45  }
46  return failureCode;
47  }
48 } // namespace
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 }
std::string string
Definition: nybbler.cc:12
const double e
int processOptions(bpo::variables_map const &vm, fhicl::intermediate_table &raw_config)
virtual int doCheckOptions(bpo::variables_map const &vm)=0
def func()
Definition: docstring.py:7
int checkOptions(bpo::variables_map const &vm)
virtual int doProcessOptions(bpo::variables_map const &vm, fhicl::intermediate_table &raw_config)=0
static QCString * s
Definition: config.cpp:1042
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33