| # Gaudi Framework, version v22r2 |

Home |  | Generated: Tue May 10 2011

# 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   friend class StatusCode;
    00035
    00036 public:
    00042   GaudiException( const std::string& Message,
    00043                   const std::string& Tag,
    00044                   const StatusCode & Code )
    00045     : m_message    ( Message    )
    00046     , m_tag        ( Tag        )
    00047     , m_code       ( Code       )
    00048     , m_previous   (     0      )
    00049     { s_proc = true; }
    00050
    00057   GaudiException( const std::string&     Message    ,
    00058                   const std::string&     Tag        ,
    00059                   const StatusCode &     Code       ,
    00060                   const GaudiException&  Exception  )
    00061     : m_message    ( Message            )
    00062     , m_tag        ( Tag                )
    00063     , m_code       ( Code               )
    00064     , m_previous   ( Exception.clone()  )
    00065     {}
    00066
    00073   GaudiException( const std::string&     Message    ,
    00074                   const std::string&     Tag        ,
    00075                   const StatusCode &     Code       ,
    00076                   const std::exception&  Exception  )
    00077     : m_message    ( Message    )
    00078     , m_tag        ( Tag        )
    00079     , m_code       ( Code       )
    00080     , m_previous   (     0      )
    00081     {
    00082       s_proc = true;
    00083       m_message += ": " + System::typeinfoName(typeid(Exception)) + ", " +
    00084                    Exception.what();
    00085     }
    00086
    00088   GaudiException( const GaudiException& Exception ) : std::exception(Exception)
    00089   {
    00090     s_proc     = true;
    00091     m_message  =   Exception.message() ;
    00092     m_tag      =   Exception.tag    () ;
    00093     m_code     =   Exception.code   () ;
    00094     m_previous = ( 0 == Exception.previous() ) ?
    00095       0 : Exception.previous()->clone() ;
    00096   }
    00097
    00099   virtual ~GaudiException() throw() {
    00100     m_code.setChecked();
    00101     if( 0 != m_previous ) { delete m_previous ; m_previous = 0 ; }
    00102     s_proc = false;
    00103   }
    00104
    00106   GaudiException& operator=( const GaudiException& Exception ) {
    00107     if ( &Exception == this ) { return *this; }
    00108     m_message  =   Exception.message() ;
    00109     m_tag      =   Exception.tag    () ;
    00110     m_code     =   Exception.code   () ;
    00111     if( 0 != m_previous ) { delete m_previous; m_previous = 0 ; }
    00112     m_previous = ( 0 == Exception.previous() ) ?
    00113       0 : Exception.previous()->clone() ;
    00114     return *this;
    00115   }
    00116
    00118   virtual const std::string&    message   () const { return m_message; }
    00119
    00121   virtual const std::string&    setMessage( const std::string& newMessage ) {
    00122     m_message = newMessage; return message() ;
    00123   }
    00124
    00126   virtual const std::string&    tag       () const { return m_tag; }
    00127
    00129   virtual const std::string&    setTag    ( const std::string& newTag     ) {
    00130     m_tag = newTag ; return tag() ;
    00131   }
    00132
    00134   virtual const StatusCode&     code      () const { return m_code; }
    00135
    00137   virtual const StatusCode&     setCode   ( const StatusCode& newStatus  ) {
    00138     m_code = newStatus; return code() ;
    00139   }
    00140
    00142   virtual GaudiException*       previous  () const { return m_previous ; }
    00143
    00145   virtual std::ostream& printOut  ( std::ostream& os = std::cerr ) const {
    00146     os << tag() << " \t " << message() ;
    00147     switch( code() ) {
    00148       case StatusCode::SUCCESS : os << "\t StatusCode=SUCCESS"    ;  break ;
    00149       case StatusCode::FAILURE : os << "\t StatusCode=FAILURE"    ;  break ;
    00150       default                  : os << "\t StatusCode=" << code() ;  break ;
    00151     }
    00152     return ( 0 != previous() ) ? previous()->printOut( os << std::endl ) : os ;
    00153   };
    00154
    00156   virtual MsgStream& printOut ( MsgStream& os ) const {
    00157     os << tag() << "\t" << message() ;
    00158     switch( code() ) {
    00159             case StatusCode::SUCCESS : os << "\t StatusCode=SUCCESS"    ;  break ;
    00160             case StatusCode::FAILURE : os << "\t StatusCode=FAILURE"    ;  break ;
    00161             default                  : os << "\t StatusCode=" << code().getCode() ;  break ;
    00162     }
    00163     return ( 0 != previous() ) ? previous()->printOut( os << endmsg ) : os ;
    00164   }
    00165
    00167   virtual GaudiException* clone() const { return new GaudiException(*this); };
    00168
    00170   virtual const char* what () const throw() { return message().c_str() ; }
    00171 protected:
    00172   mutable std::string     m_message ;
    00173   mutable std::string     m_tag     ;
    00174   mutable StatusCode      m_code    ;
    00175   mutable GaudiException* m_previous;
    00176   static bool             s_proc;
    00177 };
    00178
    00180 std::ostream& operator<< ( std::ostream& os , const GaudiException&   ge ) {
    00181   return ge.printOut( os );
    00182 }
    00183 std::ostream& operator<< ( std::ostream& os , const GaudiException*  pge )
    00184 { return (0 == pge) ?
    00185     ( os << " GaudiException* points to NULL!" ) : ( os << *pge ); }
    00186
    00188 MsgStream&    operator<< ( MsgStream& os    , const GaudiException&   ge ) {
    00189   return ge.printOut( os );
    00190 }
    00192 MsgStream&    operator<< ( MsgStream& os    , const GaudiException*  pge ) {
    00193   return (0 == pge) ?
    00194     ( os << " GaudiException* points to NULL!" ) : ( os << *pge );
    00195 }
    00196
    00197 #endif  // GAUDIKERNEL_GAUDIEXCEPTION_H

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines