The Gaudi Framework  master (594c33fa)
Gaudi::Guards::ExceptionGuard Class Reference

#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 115 of file Guards.h.

Constructor & Destructor Documentation

◆ ExceptionGuard() [1/3]

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 123 of file Guards.h.

123  {
124  try {
125  // execute the functor:
126  m_sc = fun( obj );
127  // in the case of error try use Exception Service
128  if ( svc && m_sc.isFailure() ) { m_sc = svc->handleErr( *obj, m_sc ); }
129  } catch ( const GaudiException& e ) {
130  // Use the local handler and then (if possible) the Exception Service
131  handle( e, log );
132  if ( svc ) { m_sc = svc->handle( *obj, e ); }
133  } catch ( const std::exception& e ) {
134  // Use the local handler and then (if possible) the Exception Service
135  handle( e, log );
136  if ( svc ) { m_sc = svc->handle( *obj, e ); }
137  } catch ( ... ) {
138  // Use the local handler and then (if possible) the Exception Service
139  handle( log );
140  if ( svc ) { m_sc = svc->handle( *obj ); }
141  }
142  }

◆ ~ExceptionGuard()

Gaudi::Guards::ExceptionGuard::~ExceptionGuard ( )

destructor

Definition at line 61 of file Guards.cpp.

61 { m_sc.ignore(); }

◆ ExceptionGuard() [2/3]

Gaudi::Guards::ExceptionGuard::ExceptionGuard ( )
privatedelete

◆ ExceptionGuard() [3/3]

Gaudi::Guards::ExceptionGuard::ExceptionGuard ( const ExceptionGuard )
privatedelete

Member Function Documentation

◆ code()

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

the result of function evaluation

Definition at line 148 of file Guards.h.

148 { return m_sc; }

◆ handle() [1/3]

void Gaudi::Guards::ExceptionGuard::handle ( const GaudiException e,
MsgStream s 
)
protected

local handler of GaudiException

Definition at line 34 of file Guards.cpp.

34  {
35  // the general printout
36  log << MSG::FATAL << System::typeinfoName( typeid( exc ) ) << "('" << exc.tag() << "') is caught!" << endmsg;
37  // print the detailes about the exception:
38  log << MSG::ERROR << exc << endmsg;
39  // get the status code form the exception:
40  m_sc = exc.code();
41 }

◆ handle() [2/3]

void Gaudi::Guards::ExceptionGuard::handle ( const std::exception e,
MsgStream s 
)
protected

local handler of std::exception

Definition at line 45 of file Guards.cpp.

45  {
46  // the general printout
47  log << MSG::FATAL << System::typeinfoName( typeid( exc ) ) << " is caught!" << endmsg;
48  // print the detailes abotu the exception:
49  log << MSG::ERROR << exc.what() << endmsg;
50 }

◆ handle() [3/3]

void Gaudi::Guards::ExceptionGuard::handle ( MsgStream s)
protected

local handler of UNKNOWN exceptions

Definition at line 54 of file Guards.cpp.

54  {
55  // the general printout
56  log << MSG::FATAL << "UNKNOWN exception is caught!" << endmsg;
57 }

◆ operator const StatusCode &()

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

cast operator, useful for the implicit conversions

Definition at line 150 of file Guards.h.

150 { return code(); }

◆ operator=()

ExceptionGuard& Gaudi::Guards::ExceptionGuard::operator= ( const ExceptionGuard )
privatedelete

Member Data Documentation

◆ m_sc

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

status code : result of function evaluation

Definition at line 168 of file Guards.h.


The documentation for this class was generated from the following files:
std::exception
STL class.
Gaudi.Configuration.log
log
Definition: Configuration.py:28
GaudiException
Definition: GaudiException.h:31
std::mem_fn
T mem_fn(T... args)
Gaudi::Guards::ExceptionGuard::handle
void handle(const GaudiException &e, MsgStream &s)
local handler of GaudiException
Definition: Guards.cpp:34
System::typeinfoName
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition: System.cpp:313
Gaudi::Guards::ExceptionGuard::m_sc
StatusCode m_sc
status code : result of function evaluation
Definition: Guards.h:168
StatusCode
Definition: StatusCode.h:65
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:203
MsgStream
Definition: MsgStream.h:34
MSG::FATAL
@ FATAL
Definition: IMessageSvc.h:25
StatusCode::ignore
const StatusCode & ignore() const
Allow discarding a StatusCode without warning.
Definition: StatusCode.h:139
StatusCode::isFailure
bool isFailure() const
Definition: StatusCode.h:129
IExceptionSvc::handleErr
virtual StatusCode handleErr(const INamedInterface &o, const StatusCode &s) const =0
Handle errors.
IExceptionSvc::handle
virtual StatusCode handle(const INamedInterface &o, const GaudiException &e) const =0
Handle caught GaudiExceptions.
MSG::ERROR
@ ERROR
Definition: IMessageSvc.h:25
Gaudi::Guards::ExceptionGuard::code
const StatusCode & code() const
the result of function evaluation
Definition: Guards.h:148