The Gaudi Framework  v30r4 (9b837755)
GaudiException.cpp
Go to the documentation of this file.
2 
3 #include "GaudiKernel/System.h"
4 
5 bool GaudiException::s_proc( false );
6 static const bool enableBacktrace = System::isEnvSet( "ENABLE_BACKTRACE" );
7 
8 namespace
9 {
10  inline std::string captureBacktrace( const StatusCode& code )
11  {
12  std::string backtrace;
13  if ( enableBacktrace && !code.isSuccess() ) System::backTrace( backtrace, 100, 1 );
14  return backtrace;
15  }
16 }
17 
19  : m_message( std::move( Message ) ), m_tag( std::move( Tag ) ), m_code( std::move( Code ) )
20 {
21  s_proc = true;
22  m_backTrace = captureBacktrace( Code );
23 }
24 
26  : m_message( std::move( Message ) )
27  , m_tag( std::move( Tag ) )
28  , m_code( std::move( Code ) )
29  , m_previous( Exception.clone() )
30 {
31  // Do not capture backtrace in outer chained exceptions, so only innermost exception is printed
32 }
33 
35  : m_message( std::move( Message ) ), m_tag( std::move( Tag ) ), m_code( std::move( Code ) )
36 {
37  s_proc = true;
38  m_message += ": " + System::typeinfoName( typeid( Exception ) ) + ", " + Exception.what();
39  m_backTrace = captureBacktrace( Code );
40 }
41 
43  : std::exception( Exception )
44  , m_message{Exception.message()}
45  , m_tag{Exception.tag()}
46  , m_code{Exception.code()}
47  , m_backTrace{Exception.backTrace()}
48  , m_previous{Exception.previous() ? Exception.previous()->clone() : nullptr}
49 {
50  s_proc = true;
51 }
52 
54 {
56  s_proc = false;
57 }
58 
60 {
61  m_message = Exception.message();
62  m_tag = Exception.tag();
63  m_code = Exception.code();
64  m_backTrace = Exception.backTrace();
65  m_previous.reset( Exception.previous() ? Exception.previous()->clone() : nullptr );
66  return *this;
67 }
68 
70 {
71  os << tag() << " \t " << message() << "\t StatusCode=" << code();
72  if ( !backTrace().empty() ) os << std::endl << "Exception stack trace\n" << backTrace();
73  return ( 0 != previous() ) ? previous()->printOut( os << std::endl ) : os;
74 }
75 
77 {
78  os << tag() << " \t " << message() << "\t StatusCode=" << code();
79  if ( !backTrace().empty() ) os << endmsg << "Exception stack trace\n" << backTrace();
80  return ( 0 != previous() ) ? previous()->printOut( os << endmsg ) : os;
81 }
82 
83 std::ostream& operator<<( std::ostream& os, const GaudiException& ge ) { return ge.printOut( os ); }
84 
86 {
87  return ( 0 == pge ) ? ( os << " GaudiException* points to NULL!" ) : ( os << *pge );
88 }
89 
90 MsgStream& operator<<( MsgStream& os, const GaudiException& ge ) { return ge.printOut( os ); }
91 
93 {
94  return ( 0 == pge ) ? ( os << " GaudiException* points to NULL!" ) : ( os << *pge );
95 }
virtual const std::string & message() const
error message to be printed
GaudiException & operator=(const GaudiException &Exception)
assignment operator
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
virtual const std::string & backTrace() const
return the stack trace at instantiation
Define general base for Gaudi exception.
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition: System.cpp:332
bool isSuccess() const
Definition: StatusCode.h:287
static bool s_proc
"previous" element in the linked list
T endl(T...args)
STL namespace.
const StatusCode & setChecked(bool checked=true) const
Check/uncheck StatusCode.
Definition: StatusCode.h:153
GAUDI_API int backTrace(void **addresses, const int depth)
std::string m_tag
error message
virtual const StatusCode & code() const
StatusCode for Exception.
STL class.
std::string m_message
T what(T...args)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:51
virtual GaudiException * previous() const
get the previous exception ( "previous" element in the linked list)
virtual std::ostream & printOut(std::ostream &os=std::cerr) const
methods for overloaded printout to std::ostream& and MsgStream&
virtual GaudiException * clone() const
clone operation
virtual const std::string & tag() const
name tag for the exception, or exception type
T reset(T...args)
STL class.
GAUDI_API bool isEnvSet(const char *var)
Check if an environment variable is set or not.
Definition: System.cpp:433
The Message class.
Definition: Message.h:15
std::ostream & operator<<(std::ostream &os, const GaudiException &ge)
overloaded printout to std::ostream
std::string m_backTrace
status code for exception
virtual ~GaudiException()
destructor (perform the deletion of "previous" field!)
StatusCode m_code
exception tag
STL class.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
std::unique_ptr< GaudiException > m_previous
stack trace at instantiation
GaudiException(std::string Message, std::string Tag, StatusCode Code)
Constructor (1)