| # Gaudi Framework, version v25r0 |

Home |  | Generated: Mon Feb 17 2014

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

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
GaudiException.h
Go to the documentation of this file.
1 // $Id: GaudiException.h,v 1.6 2007/12/20 18:28:33 marcocle Exp $
2 #ifndef GAUDIKERNEL_GAUDIEXCEPTION_H
3 #define GAUDIKERNEL_GAUDIEXCEPTION_H
4
5 // Include files
6 #include "GaudiKernel/Kernel.h"
7 #include "GaudiKernel/StatusCode.h"
8 #include "GaudiKernel/MsgStream.h"
9 #include "GaudiKernel/System.h"
10
11 #include <string>
12 #include <iostream>
13 #include <exception>
14
15
24 class GAUDI_API GaudiException: virtual public std::exception {
25 // friends
26 friend inline std::ostream& operator<< ( std::ostream& os ,
27 const GaudiException& ge ) ;
28 friend inline std::ostream& operator<< ( std::ostream& os ,
29 const GaudiException* pge ) ;
30 friend inline MsgStream& operator<< ( MsgStream& os ,
31 const GaudiException& ge ) ;
32 friend inline MsgStream& operator<< ( MsgStream& os ,
33 const GaudiException* pge ) ;
34 friend class StatusCode;
35
36 public:
42 GaudiException( const std::string& Message,
43 const std::string& Tag,
44 const StatusCode & Code )
45 : m_message ( Message )
46 , m_tag ( Tag )
47 , m_code ( Code )
48 , m_previous ( 0 )
49 { s_proc = true; }
50
57 GaudiException( const std::string& Message ,
58 const std::string& Tag ,
59 const StatusCode & Code ,
60 const GaudiException& Exception )
61 : m_message ( Message )
62 , m_tag ( Tag )
63 , m_code ( Code )
64 , m_previous ( Exception.clone() )
65 {}
66
73 GaudiException( const std::string& Message ,
74 const std::string& Tag ,
75 const StatusCode & Code ,
76 const std::exception& Exception )
77 : m_message ( Message )
78 , m_tag ( Tag )
79 , m_code ( Code )
80 , m_previous ( 0 )
81 {
82 s_proc = true;
83 m_message += ": " + System::typeinfoName(typeid(Exception)) + ", " +
84 Exception.what();
85 }
86
88 GaudiException( const GaudiException& Exception ) : std::exception(Exception)
89 {
90 s_proc = true;
91 m_message = Exception.message() ;
92 m_tag = Exception.tag () ;
93 m_code = Exception.code () ;
94 m_previous = ( 0 == Exception.previous() ) ?
95 0 : Exception.previous()->clone() ;
96 }
97
99 virtual ~GaudiException() throw() {
100 m_code.setChecked();
101 if( 0 != m_previous ) { delete m_previous ; m_previous = 0 ; }
102 s_proc = false;
103 }
104
106 GaudiException& operator=( const GaudiException& Exception ) {
107 if ( &Exception == this ) { return *this; }
108 m_message = Exception.message() ;
109 m_tag = Exception.tag () ;
110 m_code = Exception.code () ;
111 if( 0 != m_previous ) { delete m_previous; m_previous = 0 ; }
112 m_previous = ( 0 == Exception.previous() ) ?
113 0 : Exception.previous()->clone() ;
114 return *this;
115 }
116
118 virtual const std::string& message () const { return m_message; }
119
121 virtual const std::string& setMessage( const std::string& newMessage ) {
122 m_message = newMessage; return message() ;
123 }
124
126 virtual const std::string& tag () const { return m_tag; }
127
129 virtual const std::string& setTag ( const std::string& newTag ) {
130 m_tag = newTag ; return tag() ;
131 }
132
134 virtual const StatusCode& code () const { return m_code; }
135
137 virtual const StatusCode& setCode ( const StatusCode& newStatus ) {
138 m_code = newStatus; return code() ;
139 }
140
142 virtual GaudiException* previous () const { return m_previous ; }
143
145 virtual std::ostream& printOut ( std::ostream& os = std::cerr ) const {
146 os << tag() << " \t " << message() ;
147 switch( code() ) {
148 case StatusCode::SUCCESS : os << "\t StatusCode=SUCCESS" ; break ;
149 case StatusCode::FAILURE : os << "\t StatusCode=FAILURE" ; break ;
150 default : os << "\t StatusCode=" << code() ; break ;
151 }
152 return ( 0 != previous() ) ? previous()->printOut( os << std::endl ) : os ;
153 }
154
156 virtual MsgStream& printOut ( MsgStream& os ) const {
157 os << tag() << "\t" << message() ;
158 switch( code() ) {
159 case StatusCode::SUCCESS : os << "\t StatusCode=SUCCESS" ; break ;
160 case StatusCode::FAILURE : os << "\t StatusCode=FAILURE" ; break ;
161 default : os << "\t StatusCode=" << code().getCode() ; break ;
162 }
163 return ( 0 != previous() ) ? previous()->printOut( os << endmsg ) : os ;
164 }
165
167 virtual GaudiException* clone() const { return new GaudiException(*this); }
168
170 virtual const char* what () const throw() { return message().c_str() ; }
171 protected:
172 mutable std::string m_message ;
173 mutable std::string m_tag ;
174 mutable StatusCode m_code ;
175 mutable GaudiException* m_previous;
176 static bool s_proc;
177 };
178
180 std::ostream& operator<< ( std::ostream& os , const GaudiException& ge ) {
181 return ge.printOut( os );
182 }
183 std::ostream& operator<< ( std::ostream& os , const GaudiException* pge )
184 { return (0 == pge) ?
185 ( os << " GaudiException* points to NULL!" ) : ( os << *pge ); }
186
188 MsgStream& operator<< ( MsgStream& os , const GaudiException& ge ) {
189 return ge.printOut( os );
190 }
192 MsgStream& operator<< ( MsgStream& os , const GaudiException* pge ) {
193 return (0 == pge) ?
194 ( os << " GaudiException* points to NULL!" ) : ( os << *pge );
195 }
196
197 #endif // GAUDIKERNEL_GAUDIEXCEPTION_H