The Gaudi Framework  v30r3 (a5ef0a68)
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 ()=delete
 
 ExceptionGuard (const ExceptionGuard &)=delete
 
ExceptionGuardoperator= (const ExceptionGuard &)=delete
 

Private Attributes

StatusCode m_sc = StatusCode::FAILURE
 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_fn(&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 107 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 116 of file Guards.h.

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

destructor

Definition at line 54 of file Guards.cpp.

54 { m_sc.ignore(); }
StatusCode m_sc
status code : result of function evaluation
Definition: Guards.h:170
const StatusCode & ignore() const
Ignore/check StatusCode.
Definition: StatusCode.h:165
Gaudi::Guards::ExceptionGuard::ExceptionGuard ( )
privatedelete
Gaudi::Guards::ExceptionGuard::ExceptionGuard ( const ExceptionGuard )
privatedelete

Member Function Documentation

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

the result of function evaluation

Definition at line 150 of file Guards.h.

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

local handler of GaudiException

Definition at line 24 of file Guards.cpp.

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

local handler of std::exception

Definition at line 36 of file Guards.cpp.

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

local handler of UNKNOWN exceptions

Definition at line 46 of file Guards.cpp.

47 {
48  // the general printout
49  log << MSG::FATAL << "UNKNOWN exception is caught!" << endmsg;
50 }
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
Gaudi::Guards::ExceptionGuard::operator const StatusCode & ( ) const
inline

cast operator, useful for the implicit conversions

Definition at line 152 of file Guards.h.

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

Member Data Documentation

StatusCode Gaudi::Guards::ExceptionGuard::m_sc = StatusCode::FAILURE
private

status code : result of function evaluation

Definition at line 170 of file Guards.h.


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