LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
ExceptionCollector.h
Go to the documentation of this file.
1 #ifndef art_Framework_EventProcessor_detail_ExceptionCollector_h
2 #define art_Framework_EventProcessor_detail_ExceptionCollector_h
3 
4 // ======================================================================
5 //
6 // ExceptionCollector - Utility used to collect exceptions thrown when
7 // invoking functions that were provided to ExceptionCollector::call.
8 // The semantics are different than cet::exception_collector in that
9 // the (compiled-generated) ExceptionCollector d'tor DOES NOT call
10 // rethrow.
11 //
12 // TODO: determine if this class should be removed in favor of the
13 // cet::exception_collector class.
14 //
15 // ======================================================================
16 
17 #include <exception>
18 #include <string>
19 #include <vector>
20 
21 namespace art::detail {
23  public:
24  bool
25  empty() const noexcept
26  {
27  return exceptions_.empty();
28  }
29  [[noreturn]] void rethrow();
30 
31  template <typename F>
32  void
33  call(F f)
34  try {
35  f();
36  }
37  catch (...) {
38  exceptions_.push_back(std::current_exception());
39  }
40 
41  private:
42  std::vector<std::exception_ptr> exceptions_{};
43  };
44 
46  public:
47  explicit collected_exception(std::string msg) : msg_(std::move(msg)) {}
48  char const*
49  what() const noexcept override
50  {
51  return msg_.c_str();
52  }
53 
54  private:
55  std::string const msg_;
56  };
57 }
58 
59 #endif /* art_Framework_EventProcessor_detail_ExceptionCollector_h */
60 
61 // Local Variables:
62 // mode: c++
63 // End:
char const * what() const noexcept override
STL namespace.
TFile f
Definition: plotHisto.C:6
std::vector< std::exception_ptr > exceptions_
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33