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
7
namespace
edm
{
8
9
class
MultipleException
:
public
cms::Exception
{
10
public
:
11
MultipleException
(
int
iReturnValue,
std::string
const
& iMessage)
12
:
cms
::
Exception
(
"MultipleExceptions"
, iMessage),
returnValue_
(iReturnValue) {}
13
14
Exception
*
clone
()
const override
{
return
new
MultipleException
(*
this
); }
15
16
private
:
17
int
returnCode_
()
const override
{
return
returnValue_
; }
18
19
int
returnValue_
;
20
};
21
22
ExceptionCollector::ExceptionCollector
(
std::string
const
& initialMessage)
23
: initialMessage_(initialMessage), firstException_(), accumulatedExceptions_(), nExceptions_(0) {}
24
25
ExceptionCollector::~ExceptionCollector
() {}
26
27
bool
ExceptionCollector::hasThrown
()
const
{
return
nExceptions_
> 0; }
28
29
void
ExceptionCollector::rethrow
()
const
{
30
if
(
nExceptions_
== 1) {
31
firstException_
->raise();
32
}
else
if
(
nExceptions_
> 1) {
33
accumulatedExceptions_
->raise();
34
}
35
}
36
37
void
ExceptionCollector::call
(
std::function
<
void
(
void
)>
f
) {
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
}
46
*
accumulatedExceptions_
<<
nExceptions_
<<
"\n"
<< ex.
explainSelf
();
47
}
48
}
49
50
void
ExceptionCollector::addException
(
cms::Exception
const
&
exception
) {
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
}
60
}
// namespace edm
edm::ExceptionCollector::initialMessage_
std::string initialMessage_
Definition:
ExceptionCollector.h:43
edm::ExceptionCollector::addException
void addException(cms::Exception const &exception)
Definition:
ExceptionCollector.cc:50
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:14
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:37
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition:
AlCaHLTBitMon_QueryRunRegistry.py:256
edm::ExceptionCollector::hasThrown
bool hasThrown() const
Definition:
ExceptionCollector.cc:27
cppFunctionSkipper.exception
exception
Definition:
cppFunctionSkipper.py:10
edm::ExceptionCollector::~ExceptionCollector
~ExceptionCollector()
Definition:
ExceptionCollector.cc:25
edm::MultipleException::MultipleException
MultipleException(int iReturnValue, std::string const &iMessage)
Definition:
ExceptionCollector.cc:11
edm::ExceptionCollector::nExceptions_
int nExceptions_
Definition:
ExceptionCollector.h:46
edm::MultipleException::returnValue_
int returnValue_
Definition:
ExceptionCollector.cc:19
edm::MultipleException::returnCode_
int returnCode_() const override
Definition:
ExceptionCollector.cc:17
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:9
edm::ExceptionCollector::rethrow
void rethrow() const
Definition:
ExceptionCollector.cc:29
edm::ExceptionCollector::ExceptionCollector
ExceptionCollector(std::string const &initialMessage)
Definition:
ExceptionCollector.cc:22
cms
Namespace of DDCMS conversion namespace.
Definition:
ProducerAnalyzer.cc:21
Generated for CMSSW Reference Manual by
1.8.16