CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
edm::ExceptionCollector Class Reference

#include <ExceptionCollector.h>

Public Member Functions

void addException (cms::Exception const &exception)
 
void call (std::function< void(void)>)
 
 ExceptionCollector (std::string const &initialMessage)
 
bool hasThrown () const
 
void rethrow () const
 
 ~ExceptionCollector ()
 

Private Attributes

std::unique_ptr< cms::ExceptionaccumulatedExceptions_
 
std::unique_ptr< cms::ExceptionfirstException_
 
std::string initialMessage_
 
int nExceptions_
 

Detailed Description

Definition at line 33 of file ExceptionCollector.h.

Constructor & Destructor Documentation

◆ ExceptionCollector()

edm::ExceptionCollector::ExceptionCollector ( std::string const &  initialMessage)

Definition at line 23 of file ExceptionCollector.cc.

std::unique_ptr< cms::Exception > firstException_
std::unique_ptr< cms::Exception > accumulatedExceptions_

◆ ~ExceptionCollector()

edm::ExceptionCollector::~ExceptionCollector ( )

Definition at line 26 of file ExceptionCollector.cc.

26 {}

Member Function Documentation

◆ addException()

void edm::ExceptionCollector::addException ( cms::Exception const &  exception)

Definition at line 53 of file ExceptionCollector.cc.

References accumulatedExceptions_, cppFunctionSkipper::exception, firstException_, initialMessage_, and nExceptions_.

Referenced by edm::WorkerManager::endJob(), edm::Schedule::endJob(), and edm::SubProcess::endJob().

53  {
54  ++nExceptions_;
55  if (nExceptions_ == 1) {
56  firstException_.reset(exception.clone());
57  accumulatedExceptions_ = std::make_unique<MultipleException>(exception.returnCode(), initialMessage_);
58  }
59  *accumulatedExceptions_ << "----- Exception " << nExceptions_ << " -----"
60  << "\n"
61  << exception.explainSelf();
62  }
std::unique_ptr< cms::Exception > firstException_
std::unique_ptr< cms::Exception > accumulatedExceptions_

◆ call()

void edm::ExceptionCollector::call ( std::function< void(void)>  f)

Definition at line 38 of file ExceptionCollector.cc.

References accumulatedExceptions_, cms::Exception::clone(), cms::Exception::explainSelf(), f, firstException_, initialMessage_, nExceptions_, cms::Exception::returnCode(), and edm::convertException::wrap().

Referenced by edm::GlobalSchedule::endJob().

38  {
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  }
47  *accumulatedExceptions_ << "----- Exception " << nExceptions_ << " -----"
48  << "\n"
49  << ex.explainSelf();
50  }
51  }
int returnCode() const
Definition: Exception.cc:155
std::unique_ptr< cms::Exception > firstException_
virtual std::string explainSelf() const
Definition: Exception.cc:112
double f[11][100]
std::unique_ptr< cms::Exception > accumulatedExceptions_
auto wrap(F iFunc) -> decltype(iFunc())
virtual Exception * clone() const
Definition: Exception.cc:185

◆ hasThrown()

bool edm::ExceptionCollector::hasThrown ( ) const

◆ rethrow()

void edm::ExceptionCollector::rethrow ( ) const

Definition at line 30 of file ExceptionCollector.cc.

References accumulatedExceptions_, firstException_, and nExceptions_.

Referenced by edm::PileUp::endStream(), and edm::BMixingModule::endStream().

30  {
31  if (nExceptions_ == 1) {
32  firstException_->raise();
33  } else if (nExceptions_ > 1) {
34  accumulatedExceptions_->raise();
35  }
36  }
std::unique_ptr< cms::Exception > firstException_
std::unique_ptr< cms::Exception > accumulatedExceptions_

Member Data Documentation

◆ accumulatedExceptions_

std::unique_ptr<cms::Exception> edm::ExceptionCollector::accumulatedExceptions_
private

Definition at line 45 of file ExceptionCollector.h.

Referenced by addException(), call(), and rethrow().

◆ firstException_

std::unique_ptr<cms::Exception> edm::ExceptionCollector::firstException_
private

Definition at line 44 of file ExceptionCollector.h.

Referenced by addException(), call(), and rethrow().

◆ initialMessage_

std::string edm::ExceptionCollector::initialMessage_
private

Definition at line 43 of file ExceptionCollector.h.

Referenced by addException(), and call().

◆ nExceptions_

int edm::ExceptionCollector::nExceptions_
private

Definition at line 46 of file ExceptionCollector.h.

Referenced by addException(), call(), hasThrown(), and rethrow().