CMS 3D CMS Logo

ExceptionCollector.cc
Go to the documentation of this file.
4 
5 #include <exception>
6 #include <memory>
7 
8 namespace edm {
9 
11  public:
12  MultipleException(int iReturnValue, std::string const& iMessage)
13  : cms::Exception("MultipleExceptions", iMessage), returnValue_(iReturnValue) {}
14 
15  Exception* clone() const override { return new MultipleException(*this); }
16 
17  private:
18  int returnCode_() const override { return returnValue_; }
19 
21  };
22 
24  : initialMessage_(initialMessage), firstException_(), accumulatedExceptions_(), nExceptions_(0) {}
25 
27 
28  bool ExceptionCollector::hasThrown() const { return nExceptions_ > 0; }
29 
31  if (nExceptions_ == 1) {
32  firstException_->raise();
33  } else if (nExceptions_ > 1) {
34  accumulatedExceptions_->raise();
35  }
36  }
37 
39  try {
40  convertException::wrap([&f]() { f(); });
41  } catch (cms::Exception const& ex) {
42  ++nExceptions_;
43  if (nExceptions_ == 1) {
44  firstException_.reset(ex.clone());
45  accumulatedExceptions_ = std::make_unique<MultipleException>(ex.returnCode(), initialMessage_);
46  }
48  }
49  }
50 
52  ++nExceptions_;
53  if (nExceptions_ == 1) {
54  firstException_.reset(exception.clone());
55  accumulatedExceptions_ = std::make_unique<MultipleException>(exception.returnCode(), initialMessage_);
56  }
57  *accumulatedExceptions_ << "----- Exception " << nExceptions_ << " -----"
58  << "\n"
59  << exception.explainSelf();
60  }
61 } // namespace edm
int returnCode() const
Definition: Exception.cc:151
void addException(cms::Exception const &exception)
int returnCode_() const override
std::unique_ptr< cms::Exception > firstException_
virtual std::string explainSelf() const
Definition: Exception.cc:108
double f[11][100]
Namespace of DDCMS conversion namespace.
std::unique_ptr< cms::Exception > accumulatedExceptions_
ExceptionCollector(std::string const &initialMessage)
HLT enums.
auto wrap(F iFunc) -> decltype(iFunc())
void call(std::function< void(void)>)
Exception * clone() const override
virtual Exception * clone() const
Definition: Exception.cc:181
MultipleException(int iReturnValue, std::string const &iMessage)