All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Gaudi::Guards::ExceptionGuard Class Reference

The most simple guard - it execute the certain code withing typical "try {} catch" clause, used in Auditor, Algorithm, AlgTool, etc. More...

#include <GaudiKernel/Guards.h>

Collaboration diagram for Gaudi::Guards::ExceptionGuard:

Public Member Functions

template<class OBJECT , class FUNCTION >
 ExceptionGuard (OBJECT obj, FUNCTION fun, MsgStream &log, IExceptionSvc *svc=0)
 
 ~ExceptionGuard ()
 destructor More...
 
const StatusCodecode () const
 the result of function evaluation More...
 
 operator const StatusCode & () const
 cast operator, useful for the implicit conversions More...
 

Protected Member Functions

void handle (const GaudiException &e, MsgStream &s)
 local handler of GaudiException More...
 
void handle (const std::exception &e, MsgStream &s)
 local handler of std::exception More...
 
void handle (MsgStream &s)
 local handler of UNKNOWN exceptions More...
 

Private Member Functions

 ExceptionGuard ()
 default constructor is disabled More...
 
 ExceptionGuard (const ExceptionGuard &)
 no copy More...
 
ExceptionGuardoperator= (const ExceptionGuard &)
 no assignement More...
 

Private Attributes

StatusCode m_sc
 status code : result of function evaluation More...
 

Detailed Description

The most simple guard - it execute the certain code withing typical "try {} catch" clause, used in Auditor, Algorithm, AlgTool, etc.

. classes

The usage is fairly trivial:

// get the stream:
MsgStream& log = ... ;
// create the guard object and execute this->initialize()
// within the standard "try"-clause:
Gaudi::Guards::Guard guard
( this ,
std::mem_fun(&IAuditor::initialize) ,
log ) ;
// extract the status code"
StatusCode sc = guard.code() ;

The utility could be reused for member-function, regular functions, etc.. It could be easily combined with STL-idioms Essentially it required only the semantical validity of the expression "StatusCode sc = fun(obj)"

Author
Vanya BELYAEV ibely.nosp@m.aev@.nosp@m.physi.nosp@m.cs.s.nosp@m.yr.ed.nosp@m.u
Date
2007-03-07

Definition at line 108 of file Guards.h.

Constructor & Destructor Documentation

template<class OBJECT , class FUNCTION >
Gaudi::Guards::ExceptionGuard::ExceptionGuard ( OBJECT  obj,
FUNCTION  fun,
MsgStream log,
IExceptionSvc svc = 0 
)
inline

< execute the functor

Definition at line 118 of file Guards.h.

123  {
124  try
125  {
126  // execute the functor:
127  m_sc = fun ( obj ) ;
128  // in the case of error try use Exception Service
129  if ( 0 != svc && m_sc.isFailure() ) { m_sc = svc->handleErr ( *obj , m_sc ) ; }
130  }
131  catch ( const GaudiException& e )
132  {
133  // Use the local handler and then (if possible) the Exception Service
134  handle ( e , log ) ;
135  if ( 0 != svc ) { m_sc = svc -> handle ( *obj , e ) ; }
136  }
137  catch ( const std::exception& e )
138  {
139  // Use the local handler and then (if possible) the Exception Service
140  handle ( e , log ) ;
141  if ( 0 != svc ) { m_sc = svc -> handle ( *obj , e ) ; }
142  }
143  catch ( ... )
144  {
145  // Use the local handler and then (if possible) the Exception Service
146  handle ( log ) ;
147  if ( 0 != svc ) { m_sc = svc -> handle ( *obj ) ; }
148  }
149  }
void handle(const GaudiException &e, MsgStream &s)
local handler of GaudiException
Definition: Guards.cpp:26
Define general base for Gaudi exception.
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:72
StatusCode m_sc
status code : result of function evaluation
Definition: Guards.h:173
double fun(const std::vector< double > &x)
Definition: PFuncTest.cpp:27
virtual StatusCode handleErr(const INamedInterface &o, const StatusCode &s) const =0
Handle errors.
Gaudi::Guards::ExceptionGuard::~ExceptionGuard ( )

destructor

Definition at line 61 of file Guards.cpp.

61 { m_sc.ignore() ; }
StatusCode m_sc
status code : result of function evaluation
Definition: Guards.h:173
void ignore() const
Definition: StatusCode.h:94
Gaudi::Guards::ExceptionGuard::ExceptionGuard ( )
private

default constructor is disabled

Gaudi::Guards::ExceptionGuard::ExceptionGuard ( const ExceptionGuard )
private

no copy

Member Function Documentation

const StatusCode& Gaudi::Guards::ExceptionGuard::code ( ) const
inline

the result of function evaluation

Definition at line 154 of file Guards.h.

154 { return m_sc ; }
StatusCode m_sc
status code : result of function evaluation
Definition: Guards.h:173
void Gaudi::Guards::ExceptionGuard::handle ( const GaudiException e,
MsgStream s 
)
protected

local handler of GaudiException

Definition at line 26 of file Guards.cpp.

27 {
28  // the general printout
29  log << MSG::FATAL
30  << System::typeinfoName( typeid ( exc ) )
31  << "('" << exc.tag() << "') is caught!" << endmsg ;
32  // print the detailes about the exception:
33  log << MSG::ERROR << exc << endmsg ;
34  // get the status code form the exception:
35  m_sc = exc.code() ;
36 }
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition: System.cpp:298
StatusCode m_sc
status code : result of function evaluation
Definition: Guards.h:173
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:243
void Gaudi::Guards::ExceptionGuard::handle ( const std::exception &  e,
MsgStream s 
)
protected

local handler of std::exception

Definition at line 41 of file Guards.cpp.

42 {
43  // the general printout
44  log << MSG::FATAL
45  << System::typeinfoName( typeid ( exc ) ) << " is caught!" << endmsg ;
46  // print the detailes abotu the exception:
47  log << MSG::ERROR << exc.what() << endmsg ;
48 }
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition: System.cpp:298
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:243
void Gaudi::Guards::ExceptionGuard::handle ( MsgStream s)
protected

local handler of UNKNOWN exceptions

Definition at line 53 of file Guards.cpp.

54 {
55  // the general printout
56  log << MSG::FATAL << "UNKNOWN exception is caught!" << endmsg ;
57 }
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:243
Gaudi::Guards::ExceptionGuard::operator const StatusCode & ( ) const
inline

cast operator, useful for the implicit conversions

Definition at line 156 of file Guards.h.

156 { return code() ; }
const StatusCode & code() const
the result of function evaluation
Definition: Guards.h:154
ExceptionGuard& Gaudi::Guards::ExceptionGuard::operator= ( const ExceptionGuard )
private

no assignement

Member Data Documentation

StatusCode Gaudi::Guards::ExceptionGuard::m_sc
private

status code : result of function evaluation

Definition at line 173 of file Guards.h.


The documentation for this class was generated from the following files: