Gaudi Framework, version v21r8

Home   Generated: 17 Mar 2010

GaudiException.h

Go to the documentation of this file.
00001 // $Id: GaudiException.h,v 1.6 2007/12/20 18:28:33 marcocle Exp $
00002 #ifndef GAUDIKERNEL_GAUDIEXCEPTION_H
00003 #define GAUDIKERNEL_GAUDIEXCEPTION_H
00004 
00005 // Include files
00006 #include "GaudiKernel/Kernel.h"
00007 #include "GaudiKernel/StatusCode.h"
00008 #include "GaudiKernel/MsgStream.h"
00009 #include "GaudiKernel/System.h"
00010 
00011 #include <string>
00012 #include <iostream>
00013 #include <exception>
00014 
00015 
00024 class GAUDI_API GaudiException: virtual public std::exception {
00025   // friends
00026   friend inline std::ostream& operator<< ( std::ostream& os ,
00027                                            const GaudiException&   ge ) ;
00028   friend inline std::ostream& operator<< ( std::ostream& os ,
00029                                            const GaudiException*  pge ) ;
00030   friend inline MsgStream&    operator<< ( MsgStream&    os ,
00031                                            const GaudiException&   ge ) ;
00032   friend inline MsgStream&    operator<< ( MsgStream&    os ,
00033                                            const GaudiException*  pge ) ;
00034 
00035 public:
00041   GaudiException( const std::string& Message,
00042                   const std::string& Tag,
00043                   const StatusCode & Code )
00044     : m_message    ( Message    )
00045     , m_tag        ( Tag        )
00046     , m_code       ( Code       )
00047     , m_previous   (     0      )
00048     {}
00049 
00056   GaudiException( const std::string&     Message    ,
00057                   const std::string&     Tag        ,
00058                   const StatusCode &     Code       ,
00059                   const GaudiException&  Exception  )
00060     : m_message    ( Message            )
00061     , m_tag        ( Tag                )
00062     , m_code       ( Code               )
00063     , m_previous   ( Exception.clone()  )
00064     {}
00065 
00072   GaudiException( const std::string&     Message    ,
00073                   const std::string&     Tag        ,
00074                   const StatusCode &     Code       ,
00075                   const std::exception&  Exception  )
00076     : m_message    ( Message    )
00077     , m_tag        ( Tag        )
00078     , m_code       ( Code       )
00079     , m_previous   (     0      )
00080     {
00081       m_message += ": " + System::typeinfoName(typeid(Exception)) + ", " +
00082                    Exception.what();
00083     }
00084 
00086   GaudiException( const GaudiException& Exception ) : std::exception(Exception)
00087   {
00088     m_message  =   Exception.message() ;
00089     m_tag      =   Exception.tag    () ;
00090     m_code     =   Exception.code   () ;
00091     m_previous = ( 0 == Exception.previous() ) ?
00092       0 : Exception.previous()->clone() ;
00093   }
00094 
00096   virtual ~GaudiException() throw() {
00097     if( 0 != m_previous ) { delete m_previous ; m_previous = 0 ; }
00098   }
00099 
00101   GaudiException& operator=( const GaudiException& Exception ) {
00102     if ( &Exception == this ) { return *this; }
00103     m_message  =   Exception.message() ;
00104     m_tag      =   Exception.tag    () ;
00105     m_code     =   Exception.code   () ;
00106     if( 0 != m_previous ) { delete m_previous; m_previous = 0 ; }
00107     m_previous = ( 0 == Exception.previous() ) ?
00108       0 : Exception.previous()->clone() ;
00109     return *this;
00110   }
00111 
00113   virtual const std::string&    message   () const { return m_message; }
00114 
00116   virtual const std::string&    setMessage( const std::string& newMessage ) {
00117     m_message = newMessage; return message() ;
00118   }
00119 
00121   virtual const std::string&    tag       () const { return m_tag; }
00122 
00124   virtual const std::string&    setTag    ( const std::string& newTag     ) {
00125     m_tag = newTag ; return tag() ;
00126   }
00127 
00129   virtual const StatusCode&     code      () const { return m_code; }
00130 
00132   virtual const StatusCode&     setCode   ( const StatusCode& newStatus  ) {
00133     m_code = newStatus; return code() ;
00134   }
00135 
00137   virtual GaudiException*       previous  () const { return m_previous ; }
00138 
00140   virtual std::ostream& printOut  ( std::ostream& os = std::cerr ) const {
00141     os << tag() << " \t " << message() ;
00142     switch( code() ) {
00143       case StatusCode::SUCCESS : os << "\t StatusCode=SUCCESS"    ;  break ;
00144       case StatusCode::FAILURE : os << "\t StatusCode=FAILURE"    ;  break ;
00145       default                  : os << "\t StatusCode=" << code() ;  break ;
00146     }
00147     return ( 0 != previous() ) ? previous()->printOut( os << std::endl ) : os ;
00148   };
00149 
00151   virtual MsgStream& printOut ( MsgStream& os ) const {
00152     os << tag() << "\t" << message() ;
00153     switch( code() ) {
00154             case StatusCode::SUCCESS : os << "\t StatusCode=SUCCESS"    ;  break ;
00155             case StatusCode::FAILURE : os << "\t StatusCode=FAILURE"    ;  break ;
00156             default                  : os << "\t StatusCode=" << code().getCode() ;  break ;
00157     }
00158     return ( 0 != previous() ) ? previous()->printOut( os << endmsg ) : os ;
00159   }
00160 
00162   virtual GaudiException* clone() const { return new GaudiException(*this); };
00163 
00165   virtual const char* what () const throw() { return message().c_str() ; }
00166 protected:
00167   mutable std::string     m_message ;  
00168   mutable std::string     m_tag     ;  
00169   mutable StatusCode      m_code    ;  
00170   mutable GaudiException* m_previous;  
00171 };
00172 
00174 std::ostream& operator<< ( std::ostream& os , const GaudiException&   ge ) {
00175   return ge.printOut( os );
00176 }
00177 std::ostream& operator<< ( std::ostream& os , const GaudiException*  pge )
00178 { return (0 == pge) ?
00179     ( os << " GaudiException* points to NULL!" ) : ( os << *pge ); }
00180 
00182 MsgStream&    operator<< ( MsgStream& os    , const GaudiException&   ge ) {
00183   return ge.printOut( os );
00184 }
00186 MsgStream&    operator<< ( MsgStream& os    , const GaudiException*  pge ) {
00187   return (0 == pge) ?
00188     ( os << " GaudiException* points to NULL!" ) : ( os << *pge );
00189 }
00190 
00191 #endif  // GAUDIKERNEL_GAUDIEXCEPTION_H

Generated at Wed Mar 17 18:06:14 2010 for Gaudi Framework, version v21r8 by Doxygen version 1.5.6 written by Dimitri van Heesch, © 1997-2004