The Gaudi Framework
master (bdbe7744)
Toggle main menu visibility
Loading...
Searching...
No Matches
GaudiException.cpp
Go to the documentation of this file.
1
/***********************************************************************************\
2
* (c) Copyright 1998-2024 CERN for the benefit of the LHCb and ATLAS collaborations *
3
* *
4
* This software is distributed under the terms of the Apache version 2 licence, *
5
* copied verbatim in the file "LICENSE". *
6
* *
7
* In applying this licence, CERN does not waive the privileges and immunities *
8
* granted to it by virtue of its status as an Intergovernmental Organization *
9
* or submit itself to any jurisdiction. *
10
\***********************************************************************************/
11
#include <
GaudiKernel/GaudiException.h
>
12
13
#include <
GaudiKernel/System.h
>
14
15
bool
GaudiException::s_proc
(
false
);
16
static
const
bool
enableBacktrace =
System::isEnvSet
(
"ENABLE_BACKTRACE"
);
17
18
namespace
{
19
inline
std::string captureBacktrace(
const
StatusCode
& code ) {
20
std::string backtrace;
21
if
( enableBacktrace && !code.
isSuccess
() )
System::backTrace
( backtrace, 100, 1 );
22
return
backtrace;
23
}
24
}
// namespace
25
26
GaudiException::GaudiException
( std::string
Message
, std::string Tag,
StatusCode
Code )
27
:
m_message
(
std
::move(
Message
) ),
m_tag
(
std
::move( Tag ) ),
m_code
(
std
::move( Code ) ) {
28
s_proc
=
true
;
29
m_backTrace
= captureBacktrace(
m_code
);
30
}
31
32
GaudiException::GaudiException
( std::string
Message
, std::string Tag,
StatusCode
Code,
const
GaudiException
& Exception )
33
:
m_message
(
std
::move(
Message
) )
34
,
m_tag
(
std
::move( Tag ) )
35
,
m_code
(
std
::move( Code ) )
36
,
m_previous
( Exception.
clone
() ) {
37
// Do not capture backtrace in outer chained exceptions, so only innermost exception is printed
38
}
39
40
GaudiException::GaudiException
( std::string
Message
, std::string Tag,
StatusCode
Code,
const
std::exception& Exception )
41
:
m_message
(
std
::move(
Message
) ),
m_tag
(
std
::move( Tag ) ),
m_code
(
std
::move( Code ) ) {
42
s_proc
=
true
;
43
m_message
+=
": "
+
System::typeinfoName
(
typeid
( Exception ) ) +
", "
+ Exception.what();
44
m_backTrace
= captureBacktrace(
m_code
);
45
}
46
47
GaudiException::GaudiException
(
const
GaudiException
& Exception )
48
:
std
::exception( Exception )
49
,
m_message
{ Exception.
message
() }
50
,
m_tag
{ Exception.
tag
() }
51
,
m_code
{ Exception.
code
() }
52
,
m_backTrace
{ Exception.
backTrace
() }
53
,
m_previous
{ Exception.
previous
() ? Exception.
previous
()->
clone
() : nullptr } {
54
s_proc
=
true
;
55
}
56
57
GaudiException::~GaudiException
() throw() {
s_proc
=
false
; }
58
59
GaudiException
&
GaudiException::operator=
(
const
GaudiException
& Exception ) {
60
m_message
= Exception.message();
61
m_tag
= Exception.tag();
62
m_code
= Exception.code();
63
m_backTrace
= Exception.backTrace();
64
m_previous
.reset( Exception.previous() ? Exception.previous()->clone() :
nullptr
);
65
return
*
this
;
66
}
67
68
std::ostream&
GaudiException::printOut
( std::ostream& os )
const
{
69
os <<
tag
() <<
" \t "
<<
message
() <<
"\t StatusCode="
<<
code
();
70
if
( !
backTrace
().empty() ) os << std::endl <<
"Exception stack trace\n"
<<
backTrace
();
71
return
( 0 !=
previous
() ) ?
previous
()->
printOut
( os << std::endl ) : os;
72
}
73
74
MsgStream
&
GaudiException::printOut
(
MsgStream
& os )
const
{
75
os <<
tag
() <<
" \t "
<<
message
() <<
"\t StatusCode="
<<
code
();
76
if
( !
backTrace
().empty() ) os <<
endmsg
<<
"Exception stack trace\n"
<<
backTrace
();
77
return
( 0 !=
previous
() ) ?
previous
()->
printOut
( os <<
endmsg
) : os;
78
}
79
80
std::ostream&
operator<<
( std::ostream& os,
const
GaudiException
& ge ) {
return
ge.
printOut
( os ); }
81
82
std::ostream&
operator<<
( std::ostream& os,
const
GaudiException
* pge ) {
83
return
( 0 == pge ) ? ( os <<
" GaudiException* points to NULL!"
) : ( os << *pge );
84
}
85
86
MsgStream
&
operator<<
(
MsgStream
& os,
const
GaudiException
& ge ) {
return
ge.
printOut
( os ); }
87
88
MsgStream
&
operator<<
(
MsgStream
& os,
const
GaudiException
* pge ) {
89
return
( 0 == pge ) ? ( os <<
" GaudiException* points to NULL!"
) : ( os << *pge );
90
}
operator<<
std::ostream & operator<<(std::ostream &os, const GaudiException &ge)
Definition
GaudiException.cpp:80
GaudiException.h
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition
MsgStream.h:198
System.h
GaudiException::message
virtual const std::string & message() const
error message to be printed
Definition
GaudiException.h:66
GaudiException::s_proc
static bool s_proc
"previous" element in the linked list
Definition
GaudiException.h:128
GaudiException::code
virtual const StatusCode & code() const
StatusCode for Exception.
Definition
GaudiException.h:84
GaudiException::GaudiException
GaudiException(std::string Message, std::string Tag, StatusCode Code)
Constructor (1).
Definition
GaudiException.cpp:26
GaudiException::printOut
virtual std::ostream & printOut(std::ostream &os=std::cerr) const
methods for overloaded printout to std::ostream& and MsgStream&
Definition
GaudiException.cpp:68
GaudiException::m_message
std::string m_message
Definition
GaudiException.h:123
GaudiException::~GaudiException
virtual ~GaudiException()
destructor (perform the deletion of "previous" field!)
Definition
GaudiException.cpp:57
GaudiException::m_code
StatusCode m_code
exception tag
Definition
GaudiException.h:125
GaudiException::StatusCode
friend class StatusCode
Definition
GaudiException.h:30
GaudiException::clone
virtual GaudiException * clone() const
clone operation
Definition
GaudiException.h:105
GaudiException::m_previous
std::unique_ptr< GaudiException > m_previous
stack trace at instantiation
Definition
GaudiException.h:127
GaudiException::m_tag
std::string m_tag
error message
Definition
GaudiException.h:124
GaudiException::m_backTrace
std::string m_backTrace
status code for exception
Definition
GaudiException.h:126
GaudiException::operator=
GaudiException & operator=(const GaudiException &Exception)
assignment operator
Definition
GaudiException.cpp:59
GaudiException::backTrace
virtual const std::string & backTrace() const
return the stack trace at instantiation
Definition
GaudiException.h:96
GaudiException::previous
virtual GaudiException * previous() const
get the previous exception ( "previous" element in the linked list)
Definition
GaudiException.h:93
GaudiException::tag
virtual const std::string & tag() const
name tag for the exception, or exception type
Definition
GaudiException.h:75
Message
The Message class.
Definition
Message.h:25
MsgStream
Definition of the MsgStream class used to transmit messages.
Definition
MsgStream.h:29
StatusCode
This class is used for returning status codes from appropriate routines.
Definition
StatusCode.h:64
StatusCode::isSuccess
bool isSuccess() const
Definition
StatusCode.h:302
System::backTrace
GAUDI_API int backTrace(void **addresses, const int depth)
Definition
System.cpp:357
System::isEnvSet
GAUDI_API bool isEnvSet(const char *var)
Check if an environment variable is set or not.
Definition
System.cpp:334
System::typeinfoName
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition
System.cpp:254
std
STL namespace.
GaudiKernel
src
Lib
GaudiException.cpp
Generated on
for The Gaudi Framework by
1.17.0