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 22 of file ExceptionCollector.cc.

◆ ~ExceptionCollector()

edm::ExceptionCollector::~ExceptionCollector ( )

Definition at line 25 of file ExceptionCollector.cc.

25 {}

Member Function Documentation

◆ addException()

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

Definition at line 50 of file ExceptionCollector.cc.

50  {
51  ++nExceptions_;
52  if (nExceptions_ == 1) {
53  firstException_.reset(exception.clone());
54  accumulatedExceptions_.reset(new MultipleException(exception.returnCode(), initialMessage_));
55  }
56  *accumulatedExceptions_ << "----- Exception " << nExceptions_ << " -----"
57  << "\n"
58  << exception.explainSelf();
59  }

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

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

◆ call()

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

Definition at line 37 of file ExceptionCollector.cc.

37  {
38  try {
39  convertException::wrap([&f]() { f(); });
40  } catch (cms::Exception const& ex) {
41  ++nExceptions_;
42  if (nExceptions_ == 1) {
43  firstException_.reset(ex.clone());
44  accumulatedExceptions_.reset(new MultipleException(ex.returnCode(), initialMessage_));
45  }
47  }
48  }

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

◆ hasThrown()

bool edm::ExceptionCollector::hasThrown ( ) const

Definition at line 27 of file ExceptionCollector.cc.

27 { return nExceptions_ > 0; }

References nExceptions_.

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

◆ rethrow()

void edm::ExceptionCollector::rethrow ( ) const

Definition at line 29 of file ExceptionCollector.cc.

29  {
30  if (nExceptions_ == 1) {
31  firstException_->raise();
32  } else if (nExceptions_ > 1) {
33  accumulatedExceptions_->raise();
34  }
35  }

References accumulatedExceptions_, firstException_, and nExceptions_.

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().

edm::ExceptionCollector::initialMessage_
std::string initialMessage_
Definition: ExceptionCollector.h:43
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
edm::ExceptionCollector::accumulatedExceptions_
std::unique_ptr< cms::Exception > accumulatedExceptions_
Definition: ExceptionCollector.h:45
edm::convertException::wrap
auto wrap(F iFunc) -> decltype(iFunc())
Definition: ConvertException.h:19
edm::ExceptionCollector::firstException_
std::unique_ptr< cms::Exception > firstException_
Definition: ExceptionCollector.h:44
cppFunctionSkipper.exception
exception
Definition: cppFunctionSkipper.py:10
edm::ExceptionCollector::nExceptions_
int nExceptions_
Definition: ExceptionCollector.h:46
cms::Exception::returnCode
int returnCode() const
Definition: Exception.cc:151
cms::Exception::explainSelf
virtual std::string explainSelf() const
Definition: Exception.cc:108
cms::Exception::clone
virtual Exception * clone() const
Definition: Exception.cc:181
cms::Exception
Definition: Exception.h:70