Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

GaudiException.h

Go to the documentation of this file.
00001 // $Header: /nfs/slac/g/glast/ground/cvs/GaudiKernel/GaudiKernel/GaudiException.h,v 1.1.1.1 2001/04/18 18:14:18 tlindner 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 
00010 #include <string> 
00011 #include <iostream> 
00012 #include <exception> 
00013 
00014 
00021 class GaudiException : virtual public std::exception  {
00022   // friends 
00023   friend inline std::ostream& operator<< ( std::ostream& os , const GaudiException&   ge ) ;
00024   friend inline std::ostream& operator<< ( std::ostream& os , const GaudiException*  pge ) ;   
00025   friend inline MsgStream&    operator<< ( MsgStream&    os , const GaudiException&   ge ) ; 
00026   friend inline MsgStream&    operator<< ( MsgStream&    os , const GaudiException*  pge ) ; 
00027   
00028 public: 
00034   GaudiException( const std::string& Message, 
00035                   const std::string& Tag, 
00036                   const StatusCode & Code ) 
00037     : m_message    ( Message    ) 
00038     , m_tag        ( Tag        )  
00039     , m_code       ( Code       ) 
00040     , m_previous   (     0      ) 
00041     {}; 
00042   
00049   GaudiException( const std::string&     Message    , 
00050                   const std::string&     Tag        , 
00051                   const StatusCode &     Code       , 
00052                   const GaudiException&  Exception  )
00053     : m_message    ( Message            ) 
00054     , m_tag        ( Tag                )  
00055     , m_code       ( Code               ) 
00056     , m_previous   ( Exception.clone()  ) 
00057     {}; 
00058   
00060   GaudiException( const GaudiException& Exception ) {
00061     m_message  =   Exception.message() ;  
00062     m_tag      =   Exception.tag    () ;     
00063     m_code     =   Exception.code   () ; 
00064     m_previous = ( 0 == Exception.previous() ) ? 0 : Exception.previous()->clone() ; 
00065   }  
00066 
00068   virtual ~GaudiException() { if( 0 != m_previous ) { delete m_previous ; m_previous = 0 ; } } 
00069   
00071   GaudiException& operator=( const GaudiException& Exception ) {
00072     if ( &Exception == this ) { return *this; } 
00073     m_message  =   Exception.message() ;  
00074     m_tag      =   Exception.tag    () ;     
00075     m_code     =   Exception.code   () ; 
00076     if( 0 != m_previous ) { delete m_previous; m_previous = 0 ; } 
00077     m_previous = ( 0 == Exception.previous() ) ? 0 : Exception.previous()->clone() ; 
00078     return *this; 
00079   }
00080 
00082   virtual const std::string&    message   () const { return m_message; }  
00083   
00085   virtual const std::string&    setMessage( const std::string& newMessage ) { m_message = newMessage; return message() ; }  
00086   
00088   virtual const std::string&    tag       () const { return m_tag; }  
00089   
00091   virtual const std::string&    setTag    ( const std::string& newTag     ) { m_tag = newTag ; return tag() ; }  
00092   
00094   virtual const StatusCode&     code      () const { return m_code; }  
00095   
00097   virtual const StatusCode&     setCode   ( const StatusCode& newStatus  ) { m_code = newStatus; return code() ; } 
00098   
00100   virtual GaudiException*       previous  () const { return m_previous ; } 
00101   
00103   virtual std::ostream&         printOut  ( std::ostream& os = std::cerr ) const  {
00104     os << tag() << " \t " << message() ; 
00105     switch( code() ) {
00106       case StatusCode::SUCCESS : os << "\t StatusCode=SUCCESS"    ;  break ; 
00107       case StatusCode::FAILURE : os << "\t StatusCode=FAILURE"    ;  break ; 
00108       default                  : os << "\t StatusCode=" << code() ;  break ; 
00109     }
00110     return ( 0 != previous() ) ? previous()->printOut( os << std::endl ) : os ;
00111   }; 
00112   
00114   virtual MsgStream& printOut ( MsgStream& os ) const {
00115     os << tag() << "\t" << message() ; 
00116     switch( code() ) {
00117             case StatusCode::SUCCESS : os << "\t StatusCode=SUCCESS"    ;  break ; 
00118             case StatusCode::FAILURE : os << "\t StatusCode=FAILURE"    ;  break ; 
00119             default                  : os << "\t StatusCode=" << code() ;  break ; 
00120     }
00121     return ( 0 != previous() ) ? previous()->printOut( os << endreq ) : os ;   
00122   }
00123   
00125   virtual GaudiException*       clone() const { return new GaudiException( *this ) ;  } ; 
00126   
00128   virtual const char*           what () const { return message().c_str() ; }  
00129 protected:
00130   mutable   std::string         m_message    ;  
00131   mutable   std::string         m_tag        ;  
00132   mutable   StatusCode          m_code       ;  
00133   mutable   GaudiException*     m_previous   ;  
00134 };
00135 
00137 std::ostream& operator<< ( std::ostream& os , const GaudiException&   ge ) { return ge.printOut( os ); } 
00138 std::ostream& operator<< ( std::ostream& os , const GaudiException*  pge ) 
00139 { return (0 == pge) ? ( os << " GaudiException* points to NULL!" ) : ( os << *pge ); } 
00140 
00142 MsgStream&    operator<< ( MsgStream& os    , const GaudiException&   ge ) { 
00143   return ge.printOut( os ); 
00144 } 
00146 MsgStream&    operator<< ( MsgStream& os    , const GaudiException*  pge ) { 
00147   return (0 == pge) ? ( os << " GaudiException* points to NULL!" ) : ( os << *pge );
00148 } 
00149 
00150 #endif  // GAUDIKERNEL_GAUDIEXCEPTION_H

Generated at Wed Nov 21 12:22:03 2001 by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000