FWCore
Utilities
src
ExceptionCollector.cc
Go to the documentation of this file.
1
#include "
FWCore/Utilities/interface/ExceptionCollector.h
"
2
#include "
FWCore/Utilities/interface/Exception.h
"
3
#include "
FWCore/Utilities/interface/ConvertException.h
"
4
5
#include <exception>
6
#include <memory>
7
8
namespace
edm
{
9
10
class
MultipleException
:
public
cms::Exception
{
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
20
int
returnValue_
;
21
};
22
23
ExceptionCollector::ExceptionCollector
(
std::string
const
& initialMessage)
24
: initialMessage_(initialMessage), firstException_(), accumulatedExceptions_(), nExceptions_(0) {}
25
26
ExceptionCollector::~ExceptionCollector
() {}
27
28
bool
ExceptionCollector::hasThrown
()
const
{
return
nExceptions_
> 0; }
29
30
void
ExceptionCollector::rethrow
()
const
{
31
if
(
nExceptions_
== 1) {
32
firstException_
->raise();
33
}
else
if
(
nExceptions_
> 1) {
34
accumulatedExceptions_
->raise();
35
}
36
}
37
38
void
ExceptionCollector::call
(
std::function
<
void
(
void
)>
f
) {
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_
<<
nExceptions_
<<
"\n"
<< ex.
explainSelf
();
48
}
49
}
50
51
void
ExceptionCollector::addException
(
cms::Exception
const
&
exception
) {
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
edm::ExceptionCollector::initialMessage_
std::string initialMessage_
Definition:
ExceptionCollector.h:43
edm::ExceptionCollector::addException
void addException(cms::Exception const &exception)
Definition:
ExceptionCollector.cc:51
f
double f[11][100]
Definition:
MuScleFitUtils.cc:78
edm
HLT enums.
Definition:
AlignableModifier.h:19
edm::ExceptionCollector::accumulatedExceptions_
std::unique_ptr< cms::Exception > accumulatedExceptions_
Definition:
ExceptionCollector.h:45
edm::MultipleException::clone
Exception * clone() const override
Definition:
ExceptionCollector.cc:15
edm::Exception
Definition:
EDMException.h:77
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
ConvertException.h
ExceptionCollector.h
edm::ExceptionCollector::call
void call(std::function< void(void)>)
Definition:
ExceptionCollector.cc:38
edm::ExceptionCollector::hasThrown
bool hasThrown() const
Definition:
ExceptionCollector.cc:28
cppFunctionSkipper.exception
exception
Definition:
cppFunctionSkipper.py:10
edm::ExceptionCollector::~ExceptionCollector
~ExceptionCollector()
Definition:
ExceptionCollector.cc:26
edm::MultipleException::MultipleException
MultipleException(int iReturnValue, std::string const &iMessage)
Definition:
ExceptionCollector.cc:12
edm::ExceptionCollector::nExceptions_
int nExceptions_
Definition:
ExceptionCollector.h:46
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition:
AlCaHLTBitMon_QueryRunRegistry.py:256
edm::MultipleException::returnValue_
int returnValue_
Definition:
ExceptionCollector.cc:20
edm::MultipleException::returnCode_
int returnCode_() const override
Definition:
ExceptionCollector.cc:18
cms::Exception::returnCode
int returnCode() const
Definition:
Exception.cc:151
HiBiasedCentrality_cfi.function
function
Definition:
HiBiasedCentrality_cfi.py:4
cms::Exception::explainSelf
virtual std::string explainSelf() const
Definition:
Exception.cc:108
cms::Exception::clone
virtual Exception * clone() const
Definition:
Exception.cc:181
Exception.h
cms::Exception
Definition:
Exception.h:70
edm::MultipleException
Definition:
ExceptionCollector.cc:10
edm::ExceptionCollector::rethrow
void rethrow() const
Definition:
ExceptionCollector.cc:30
edm::ExceptionCollector::ExceptionCollector
ExceptionCollector(std::string const &initialMessage)
Definition:
ExceptionCollector.cc:23
cms
Namespace of DDCMS conversion namespace.
Definition:
ProducerAnalyzer.cc:21
Generated for CMSSW Reference Manual by
1.8.16