| The Gaudi Framework v29r1 (5cd95fa2)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

GaudiException.h
Go to the documentation of this file.
1 #ifndef GAUDIKERNEL_GAUDIEXCEPTION_H
2 #define GAUDIKERNEL_GAUDIEXCEPTION_H
3
4 // Include files
5 #include "GaudiKernel/Kernel.h"
6 #include "GaudiKernel/MsgStream.h"
7 #include "GaudiKernel/StatusCode.h"
8 #include "GaudiKernel/System.h"
9
10 #include <exception>
11 #include <iostream>
12 #include <string>
13
22 class GAUDI_API GaudiException : virtual public std::exception
23 {
24 // friends
25 friend inline std::ostream& operator<<( std::ostream& os, const GaudiException& ge );
26 friend inline std::ostream& operator<<( std::ostream& os, const GaudiException* pge );
27 friend inline MsgStream& operator<<( MsgStream& os, const GaudiException& ge );
28 friend inline MsgStream& operator<<( MsgStream& os, const GaudiException* pge );
29 friend class StatusCode;
30
31 public:
37 GaudiException( std::string Message, std::string Tag, StatusCode Code )
38 : m_message( std::move( Message ) ), m_tag( std::move( Tag ) ), m_code( std::move( Code ) )
39 {
40 s_proc = true;
41 }
42
49 GaudiException( std::string Message, std::string Tag, StatusCode Code, const GaudiException& Exception )
50 : m_message( std::move( Message ) )
51 , m_tag( std::move( Tag ) )
52 , m_code( std::move( Code ) )
53 , m_previous( Exception.clone() )
54 {
55 }
56
63 GaudiException( std::string Message, std::string Tag, StatusCode Code, const std::exception& Exception )
64 : m_message( std::move( Message ) ), m_tag( std::move( Tag ) ), m_code( std::move( Code ) )
65 {
66 s_proc = true;
67 m_message += ": " + System::typeinfoName( typeid( Exception ) ) + ", " + Exception.what();
68 }
69
71 GaudiException( const GaudiException& Exception )
72 : std::exception( Exception )
73 , m_message{Exception.message()}
74 , m_tag{Exception.tag()}
75 , m_code{Exception.code()}
76 , m_previous{Exception.previous() ? Exception.previous()->clone() : nullptr}
77 {
78 s_proc = true;
79 }
80
82 virtual ~GaudiException() throw()
83 {
84 m_code.setChecked();
85 s_proc = false;
86 }
87
89 GaudiException& operator=( const GaudiException& Exception )
90 {
91 m_message = Exception.message();
92 m_tag = Exception.tag();
93 m_code = Exception.code();
94 m_previous.reset( Exception.previous() ? Exception.previous()->clone() : nullptr );
95 return *this;
96 }
97
99 virtual const std::string& message() const { return m_message; }
100
102 virtual const std::string& setMessage( const std::string& newMessage )
103 {
104 m_message = newMessage;
105 return message();
106 }
107
109 virtual const std::string& tag() const { return m_tag; }
110
112 virtual const std::string& setTag( const std::string& newTag )
113 {
114 m_tag = newTag;
115 return tag();
116 }
117
119 virtual const StatusCode& code() const { return m_code; }
120
122 virtual const StatusCode& setCode( const StatusCode& newStatus )
123 {
124 m_code = newStatus;
125 return code();
126 }
127
129 virtual GaudiException* previous() const { return m_previous.get(); }
130
132 virtual std::ostream& printOut( std::ostream& os = std::cerr ) const
133 {
134 os << tag() << " \t " << message();
135 switch ( code() ) {
136 case StatusCode::SUCCESS:
137 os << "\t StatusCode=SUCCESS";
138 break;
139 case StatusCode::FAILURE:
140 os << "\t StatusCode=FAILURE";
141 break;
142 default:
143 os << "\t StatusCode=" << code();
144 break;
145 }
146 return ( 0 != previous() ) ? previous()->printOut( os << std::endl ) : os;
147 }
148
150 virtual MsgStream& printOut( MsgStream& os ) const
151 {
152 os << tag() << "\t" << message();
153 switch ( code() ) {
154 case StatusCode::SUCCESS:
155 os << "\t StatusCode=SUCCESS";
156 break;
157 case StatusCode::FAILURE:
158 os << "\t StatusCode=FAILURE";
159 break;
160 default:
161 os << "\t StatusCode=" << code().getCode();
162 break;
163 }
164 return ( 0 != previous() ) ? previous()->printOut( os << endmsg ) : os;
165 }
166
168 virtual GaudiException* clone() const { return new GaudiException( *this ); }
169
171 const char* what() const throw() override { return message().c_str(); }
172
173 protected:
174 mutable std::string m_message;
175 mutable std::string m_tag;
176 mutable StatusCode m_code;
177 mutable std::unique_ptr<GaudiException> m_previous;
178 static bool s_proc;
179 };
180
182 std::ostream& operator<<( std::ostream& os, const GaudiException& ge ) { return ge.printOut( os ); }
183 std::ostream& operator<<( std::ostream& os, const GaudiException* pge )
184 {
185 return ( 0 == pge ) ? ( os << " GaudiException* points to NULL!" ) : ( os << *pge );
186 }
187
189 MsgStream& operator<<( MsgStream& os, const GaudiException& ge ) { return ge.printOut( os ); }
191 MsgStream& operator<<( MsgStream& os, const GaudiException* pge )
192 {
193 return ( 0 == pge ) ? ( os << " GaudiException* points to NULL!" ) : ( os << *pge );
194 }
195
196 #endif // GAUDIKERNEL_GAUDIEXCEPTION_H
System.h
GaudiException::message
virtual const std::string & message() const
error message to be printed
Definition: GaudiException.h:99
MsgStream
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
StatusCode::SUCCESS
Definition: StatusCode.h:31
Kernel.h
GaudiException
Define general base for Gaudi exception.
Definition: GaudiException.h:22
GaudiException::setCode
virtual const StatusCode & setCode(const StatusCode &newStatus)
update the status code for the exception
Definition: GaudiException.h:122
StatusCode::FAILURE
Definition: StatusCode.h:31
MsgStream.h
GaudiException::GaudiException
GaudiException(std::string Message, std::string Tag, StatusCode Code, const GaudiException &Exception)
Constructor (2)
Definition: GaudiException.h:49
System::typeinfoName
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition: System.cpp:329
GaudiException::operator=
GaudiException & operator=(const GaudiException &Exception)
assignment operator
Definition: GaudiException.h:89
GaudiException::s_proc
static bool s_proc
"previous" element in the linked list
Definition: GaudiException.h:178
GaudiException::setMessage
virtual const std::string & setMessage(const std::string &newMessage)
update the error message to be printed
Definition: GaudiException.h:102
std::endl
T endl(T...args)
std
STL namespace.
operator<<
std::ostream & operator<<(std::ostream &os, const GaudiException &ge)
overloaded printout to std::ostream
Definition: GaudiException.h:182
GaudiException::what
const char * what() const override
method from std::exception
Definition: GaudiException.h:171
GaudiException::m_tag
std::string m_tag
error message
Definition: GaudiException.h:175
GaudiException::code
virtual const StatusCode & code() const
StatusCode for Exception.
Definition: GaudiException.h:119
std::string
STL class.
GaudiException::m_message
std::string m_message
Definition: GaudiException.h:174
std::exception::what
T what(T...args)
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:28
GaudiException::previous
virtual GaudiException * previous() const
get the previous exception ( "previous" element in the linked list)
Definition: GaudiException.h:129
GaudiException::clone
virtual GaudiException * clone() const
clone operation
Definition: GaudiException.h:168
GaudiException::tag
virtual const std::string & tag() const
name tag for the exception, or exception type
Definition: GaudiException.h:109
GaudiException::GaudiException
GaudiException(std::string Message, std::string Tag, StatusCode Code, const std::exception &Exception)
Constructor (3)
Definition: GaudiException.h:63
std::exception
STL class.
std::unique_ptr< GaudiException >
GaudiException::printOut
virtual MsgStream & printOut(MsgStream &os) const
Output the exception to the Gaudi MsgStream.
Definition: GaudiException.h:150
Message
The Message class.
Definition: Message.h:15
GaudiException::setTag
virtual const std::string & setTag(const std::string &newTag)
update name tag
Definition: GaudiException.h:112
GaudiException::printOut
virtual std::ostream & printOut(std::ostream &os=std::cerr) const
methods for overloaded printout to std::ostream& and MsgStream&
Definition: GaudiException.h:132
GaudiException::~GaudiException
virtual ~GaudiException()
destructor (perform the deletion of "previous" field!)
Definition: GaudiException.h:82
GaudiException::m_code
StatusCode m_code
exception tag
Definition: GaudiException.h:176
StatusCode.h
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:110
std::ostream
STL class.
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
GaudiException::m_previous
std::unique_ptr< GaudiException > m_previous
status code for exception
Definition: GaudiException.h:177
GaudiException::GaudiException
GaudiException(const GaudiException &Exception)
Copy constructor (deep copying!)
Definition: GaudiException.h:71
GaudiException::GaudiException
GaudiException(std::string Message, std::string Tag, StatusCode Code)
Constructor (1)
Definition: GaudiException.h:37