| The Gaudi Framework v28r2p1 (f1a77ff4)

- 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/StatusCode.h"
7 #include "GaudiKernel/MsgStream.h"
8 #include "GaudiKernel/System.h"
9
10 #include <string>
11 #include <iostream>
12 #include <exception>
13
14
23 class GAUDI_API GaudiException: virtual public std::exception {
24 // friends
25 friend inline std::ostream& operator<< ( std::ostream& os ,
26 const GaudiException& ge ) ;
27 friend inline std::ostream& operator<< ( std::ostream& os ,
28 const GaudiException* pge ) ;
29 friend inline MsgStream& operator<< ( MsgStream& os ,
30 const GaudiException& ge ) ;
31 friend inline MsgStream& operator<< ( MsgStream& os ,
32 const GaudiException* pge ) ;
33 friend class StatusCode;
34
35 public:
41 GaudiException( std::string Message,
42 std::string Tag,
43 StatusCode Code )
44 : m_message ( std::move(Message) )
45 , m_tag ( std::move(Tag) )
46 , m_code ( std::move(Code) )
47 { s_proc = true; }
48
55 GaudiException( std::string Message ,
56 std::string Tag ,
57 StatusCode Code ,
58 const GaudiException& Exception )
59 : m_message ( std::move(Message) )
60 , m_tag ( std::move(Tag) )
61 , m_code ( std::move(Code) )
62 , m_previous ( Exception.clone() )
63 {}
64
71 GaudiException( std::string Message ,
72 std::string Tag ,
73 StatusCode Code ,
74 const std::exception& Exception )
75 : m_message ( std::move(Message) )
76 , m_tag ( std::move(Tag) )
77 , m_code ( std::move(Code) )
78 {
79 s_proc = true;
80 m_message += ": " + System::typeinfoName(typeid(Exception)) + ", " +
81 Exception.what();
82 }
83
85 GaudiException( const GaudiException& Exception )
86 : std::exception(Exception)
87 , m_message{ Exception.message() }
88 , m_tag { Exception.tag () }
89 , m_code { Exception.code () }
90 , m_previous{ Exception.previous() ? Exception.previous()->clone() : nullptr }
91 {
92 s_proc = true;
93 }
94
96 virtual ~GaudiException() throw() {
97 m_code.setChecked();
98 s_proc = false;
99 }
100
102 GaudiException& operator=( const GaudiException& Exception ) {
103 m_message = Exception.message() ;
104 m_tag = Exception.tag () ;
105 m_code = Exception.code () ;
106 m_previous.reset( Exception.previous() ? Exception.previous()->clone() : nullptr );
107 return *this;
108 }
109
111 virtual const std::string& message () const { return m_message; }
112
114 virtual const std::string& setMessage( const std::string& newMessage ) {
115 m_message = newMessage; return message() ;
116 }
117
119 virtual const std::string& tag () const { return m_tag; }
120
122 virtual const std::string& setTag ( const std::string& newTag ) {
123 m_tag = newTag ; return tag() ;
124 }
125
127 virtual const StatusCode& code () const { return m_code; }
128
130 virtual const StatusCode& setCode ( const StatusCode& newStatus ) {
131 m_code = newStatus; return code() ;
132 }
133
135 virtual GaudiException* previous () const { return m_previous.get() ; }
136
138 virtual std::ostream& printOut ( std::ostream& os = std::cerr ) const {
139 os << tag() << " \t " << message() ;
140 switch( code() ) {
141 case StatusCode::SUCCESS : os << "\t StatusCode=SUCCESS" ; break ;
142 case StatusCode::FAILURE : os << "\t StatusCode=FAILURE" ; break ;
143 default : os << "\t StatusCode=" << code() ; break ;
144 }
145 return ( 0 != previous() ) ? previous()->printOut( os << std::endl ) : os ;
146 }
147
149 virtual MsgStream& printOut ( MsgStream& os ) const {
150 os << tag() << "\t" << message() ;
151 switch( code() ) {
152 case StatusCode::SUCCESS : os << "\t StatusCode=SUCCESS" ; break ;
153 case StatusCode::FAILURE : os << "\t StatusCode=FAILURE" ; break ;
154 default : os << "\t StatusCode=" << code().getCode() ; break ;
155 }
156 return ( 0 != previous() ) ? previous()->printOut( os << endmsg ) : os ;
157 }
158
160 virtual GaudiException* clone() const { return new GaudiException(*this); }
161
163 const char* what () const throw() override { return message().c_str() ; }
164 protected:
165 mutable std::string m_message ;
166 mutable std::string m_tag ;
167 mutable StatusCode m_code ;
168 mutable std::unique_ptr<GaudiException> m_previous;
169 static bool s_proc;
170 };
171
173 std::ostream& operator<< ( std::ostream& os , const GaudiException& ge ) {
174 return ge.printOut( os );
175 }
176 std::ostream& operator<< ( std::ostream& os , const GaudiException* pge )
177 { return (0 == pge) ?
178 ( os << " GaudiException* points to NULL!" ) : ( os << *pge ); }
179
181 MsgStream& operator<< ( MsgStream& os , const GaudiException& ge ) {
182 return ge.printOut( os );
183 }
185 MsgStream& operator<< ( MsgStream& os , const GaudiException* pge ) {
186 return (0 == pge) ?
187 ( os << " GaudiException* points to NULL!" ) : ( os << *pge );
188 }
189
190 #endif // GAUDIKERNEL_GAUDIEXCEPTION_H
System.h
GaudiException::message
virtual const std::string & message() const
error message to be printed
Definition: GaudiException.h:111
MsgStream
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
StatusCode::SUCCESS
Definition: StatusCode.h:30
Kernel.h
GaudiException
Define general base for Gaudi exception.
Definition: GaudiException.h:23
GaudiException::setCode
virtual const StatusCode & setCode(const StatusCode &newStatus)
update the status code for the exception
Definition: GaudiException.h:130
StatusCode::FAILURE
Definition: StatusCode.h:29
MsgStream.h
GaudiException::GaudiException
GaudiException(std::string Message, std::string Tag, StatusCode Code, const GaudiException &Exception)
Constructor (2)
Definition: GaudiException.h:55
System::typeinfoName
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition: System.cpp:299
GaudiException::operator=
GaudiException & operator=(const GaudiException &Exception)
assignment operator
Definition: GaudiException.h:102
GaudiException::s_proc
static bool s_proc
"previous" element in the linked list
Definition: GaudiException.h:169
GaudiException::setMessage
virtual const std::string & setMessage(const std::string &newMessage)
update the error message to be printed
Definition: GaudiException.h:114
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:173
GaudiException::what
const char * what() const override
method from std::exception
Definition: GaudiException.h:163
GaudiException::m_tag
std::string m_tag
error message
Definition: GaudiException.h:166
GaudiException::code
virtual const StatusCode & code() const
StatusCode for Exception.
Definition: GaudiException.h:127
std::string
STL class.
GaudiException::m_message
std::string m_message
Definition: GaudiException.h:165
std::exception::what
T what(T...args)
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
GaudiException::previous
virtual GaudiException * previous() const
get the previous exception ( "previous" element in the linked list)
Definition: GaudiException.h:135
GaudiException::clone
virtual GaudiException * clone() const
clone operation
Definition: GaudiException.h:160
GaudiException::tag
virtual const std::string & tag() const
name tag for the exception, or exception type
Definition: GaudiException.h:119
GaudiException::GaudiException
GaudiException(std::string Message, std::string Tag, StatusCode Code, const std::exception &Exception)
Constructor (3)
Definition: GaudiException.h:71
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:149
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:122
GaudiException::printOut
virtual std::ostream & printOut(std::ostream &os=std::cerr) const
methods for overloaded printout to std::ostream& and MsgStream&
Definition: GaudiException.h:138
GaudiException::~GaudiException
virtual ~GaudiException()
destructor (perform the deletion of "previous" field!)
Definition: GaudiException.h:96
GaudiException::m_code
StatusCode m_code
exception tag
Definition: GaudiException.h:167
StatusCode.h
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:107
std::ostream
STL class.
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
GaudiException::m_previous
std::unique_ptr< GaudiException > m_previous
status code for exception
Definition: GaudiException.h:168
GaudiException::GaudiException
GaudiException(const GaudiException &Exception)
Copy constructor (deep copying!)
Definition: GaudiException.h:85
GaudiException::GaudiException
GaudiException(std::string Message, std::string Tag, StatusCode Code)
Constructor (1)
Definition: GaudiException.h:41