| The Gaudi Framework v28r2p1 (f1a77ff4)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
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:
[legend]

## Public Member Functions
template<class OBJECT , class FUNCTION >
| ExceptionGuard (OBJECT obj, FUNCTION fun, MsgStream &log, IExceptionSvc *svc=0)
| ~ExceptionGuard ()
| destructor More...
const StatusCode & | code () 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
ExceptionGuard & | operator= (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 117 of file Guards.h.

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

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

destructor

Definition at line 60 of file Guards.cpp.

60 { m_sc.ignore() ; }
Gaudi::Guards::ExceptionGuard::m_sc
StatusCode m_sc
status code : result of function evaluation
Definition: Guards.h:169
StatusCode::ignore
void ignore() const
Definition: StatusCode.h:106

Gaudi::Guards::ExceptionGuard::ExceptionGuard | ( |  | ) |
| private delete

Gaudi::Guards::ExceptionGuard::ExceptionGuard | ( | const ExceptionGuard & |  | ) |
| private delete

## Member Function Documentation

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

the result of function evaluation

Definition at line 152 of file Guards.h.

152 { return m_sc ; }
Gaudi::Guards::ExceptionGuard::m_sc
StatusCode m_sc
status code : result of function evaluation
Definition: Guards.h:169

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

local handler of GaudiException

Definition at line 25 of file Guards.cpp.

26 {
27 // the general printout
28 log << MSG::FATAL
29 << System::typeinfoName( typeid ( exc ) )
30 << "('" << exc.tag() << "') is caught!" << endmsg ;
31 // print the detailes about the exception:
32 log << MSG::ERROR << exc << endmsg ;
33 // get the status code form the exception:
34 m_sc = exc.code() ;
35 }
System::typeinfoName
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition: System.cpp:299
Gaudi::Guards::ExceptionGuard::m_sc
StatusCode m_sc
status code : result of function evaluation
Definition: Guards.h:169
MSG::FATAL
Definition: IMessageSvc.h:22
MSG::ERROR
Definition: IMessageSvc.h:21
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
Gaudi.Configuration.log
log
Definition: Configuration.py:13

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

local handler of std::exception

Definition at line 40 of file Guards.cpp.

41 {
42 // the general printout
43 log << MSG::FATAL
44 << System::typeinfoName( typeid ( exc ) ) << " is caught!" << endmsg ;
45 // print the detailes abotu the exception:
46 log << MSG::ERROR << exc.what() << endmsg ;
47 }
System::typeinfoName
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition: System.cpp:299
MSG::FATAL
Definition: IMessageSvc.h:22
MSG::ERROR
Definition: IMessageSvc.h:21
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
Gaudi.Configuration.log
log
Definition: Configuration.py:13

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

local handler of UNKNOWN exceptions

Definition at line 52 of file Guards.cpp.

53 {
54 // the general printout
55 log << MSG::FATAL << "UNKNOWN exception is caught!" << endmsg ;
56 }
MSG::FATAL
Definition: IMessageSvc.h:22
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
Gaudi.Configuration.log
log
Definition: Configuration.py:13

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

cast operator, useful for the implicit conversions

Definition at line 154 of file Guards.h.

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

ExceptionGuard& Gaudi::Guards::ExceptionGuard::operator= | ( | const ExceptionGuard & |  | ) |
| private delete

## Member Data Documentation

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

status code : result of function evaluation

Definition at line 169 of file Guards.h.

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

- GaudiKernel/GaudiKernel/Guards.h
- GaudiKernel/src/Lib/Guards.cpp