Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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  inline std::string captureBacktrace( const StatusCode& code ) {
10  std::string backtrace;
11  if ( enableBacktrace && !code.isSuccess() ) System::backTrace( backtrace, 100, 1 );
12  return backtrace;
13  }
14 } // namespace
15 
17  : m_message( std::move( Message ) ), m_tag( std::move( Tag ) ), m_code( std::move( Code ) ) {
18  s_proc = true;
19  m_backTrace = captureBacktrace( Code );
20 }
21 
23  : m_message( std::move( Message ) )
24  , m_tag( std::move( Tag ) )
25  , m_code( std::move( Code ) )
26  , m_previous( Exception.clone() ) {
27  // Do not capture backtrace in outer chained exceptions, so only innermost exception is printed
28 }
29 
31  : m_message( std::move( Message ) ), m_tag( std::move( Tag ) ), m_code( std::move( Code ) ) {
32  s_proc = true;
33  m_message += ": " + System::typeinfoName( typeid( Exception ) ) + ", " + Exception.what();
34  m_backTrace = captureBacktrace( Code );
35 }
36 
38  : std::exception( Exception )
39  , m_message{Exception.message()}
40  , m_tag{Exception.tag()}
41  , m_code{Exception.code()}
42  , m_backTrace{Exception.backTrace()}
43  , m_previous{Exception.previous() ? Exception.previous()->clone() : nullptr} {
44  s_proc = true;
45 }
46 
49  s_proc = false;
50 }
51 
53  m_message = Exception.message();
54  m_tag = Exception.tag();
55  m_code = Exception.code();
56  m_backTrace = Exception.backTrace();
57  m_previous.reset( Exception.previous() ? Exception.previous()->clone() : nullptr );
58  return *this;
59 }
60 
62  os << tag() << " \t " << message() << "\t StatusCode=" << code();
63  if ( !backTrace().empty() ) os << std::endl << "Exception stack trace\n" << backTrace();
64  return ( 0 != previous() ) ? previous()->printOut( os << std::endl ) : os;
65 }
66 
68  os << tag() << " \t " << message() << "\t StatusCode=" << code();
69  if ( !backTrace().empty() ) os << endmsg << "Exception stack trace\n" << backTrace();
70  return ( 0 != previous() ) ? previous()->printOut( os << endmsg ) : os;
71 }
72 
73 std::ostream& operator<<( std::ostream& os, const GaudiException& ge ) { return ge.printOut( os ); }
74 
76  return ( 0 == pge ) ? ( os << " GaudiException* points to NULL!" ) : ( os << *pge );
77 }
78 
79 MsgStream& operator<<( MsgStream& os, const GaudiException& ge ) { return ge.printOut( os ); }
80 
82  return ( 0 == pge ) ? ( os << " GaudiException* points to NULL!" ) : ( os << *pge );
83 }
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:309
bool isSuccess() const
Definition: StatusCode.h:267
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:143
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:50
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:400
The Message class.
Definition: Message.h:17
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:192
std::unique_ptr< GaudiException > m_previous
stack trace at instantiation
GaudiException(std::string Message, std::string Tag, StatusCode Code)
Constructor (1)