/
githubmirror
/
cmssw
Обзор
Документация
Войти
/
githubmirror
/
cmssw
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
FWCore/Utilities/src/ExceptionCollector.cc
63 строки
2 KB
W. David Dagenhart
Improve behavior after exception in begin/end transitions
19 июл 2024, 22:02
19 июл 2024, 22:02
af8027d
Код
Авторство
О чём код?
#include "FWCore/Utilities/interface/ExceptionCollector.h" #include "FWCore/Utilities/interface/Exception.h" #include "FWCore/Utilities/interface/ConvertException.h" #include <exception> #include <memory> namespace edm { class MultipleException : public cms::Exception { public: MultipleException(int iReturnValue, std::string const& iMessage) : cms::Exception("MultipleExceptions", iMessage), returnValue_(iReturnValue) {} Exception* clone() const override { return new MultipleException(*this); } private: int returnCode_() const override { return returnValue_; } int returnValue_; }; ExceptionCollector::ExceptionCollector(std::string const& initialMessage) : initialMessage_(initialMessage), firstException_(), accumulatedExceptions_(), nExceptions_(0) {} ExceptionCollector::~ExceptionCollector() {} bool ExceptionCollector::hasThrown() const { return nExceptions_ > 0; } void ExceptionCollector::rethrow() const { if (nExceptions_ == 1) { firstException_->raise(); } else if (nExceptions_ > 1) { accumulatedExceptions_->raise(); } } void ExceptionCollector::call(std::function<void(void)> f) { try { convertException::wrap([&f]() { f(); }); } catch (cms::Exception const& ex) { ++nExceptions_; if (nExceptions_ == 1) { firstException_.reset(ex.clone()); accumulatedExceptions_ = std::make_unique<MultipleException>(ex.returnCode(), initialMessage_); } *accumulatedExceptions_ << "----- Exception " << nExceptions_ << " -----" << "\n" << ex.explainSelf(); } } void ExceptionCollector::addException(cms::Exception const& exception) { ++nExceptions_; if (nExceptions_ == 1) { firstException_.reset(exception.clone()); accumulatedExceptions_ = std::make_unique<MultipleException>(exception.returnCode(), initialMessage_); } *accumulatedExceptions_ << "----- Exception " << nExceptions_ << " -----" << "\n" << exception.explainSelf(); } } // namespace edm