| # Gaudi Framework, version v22r4 |

Home |  | Generated: Fri Sep 2 2011

Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes

# 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]

List of all members.

## Public Member Functions
template<class OBJECT , class FUNCTION >
| ExceptionGuard (OBJECT obj, FUNCTION fun, MsgStream &log, IExceptionSvc *svc=0)
| ~ExceptionGuard ()
| destructor
const StatusCode & | code () const
| the result of function evaluation
| operator const StatusCode & () const
| cast operator, useful for the implicit conversions
## Protected Member Functions
void | handle (const GaudiException &e, MsgStream &s)
| local handler of GaudiException
void | handle (const std::exception &e, MsgStream &s)
| local handler of std::exception
void | handle (MsgStream &s)
| local handler of UNKNOWN exceptions
## Private Member Functions
| ExceptionGuard ()
| default constructor is disabled
| ExceptionGuard (const ExceptionGuard &)
| no copy
ExceptionGuard & | operator= (const ExceptionGuard &)
| no assignement
## Private Attributes
StatusCode | m_sc
| status code : result of function evaluation

## 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 ibelyaev@physics.syr.edu

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.

            : m_sc  ( StatusCode::FAILURE )
          {
            try
            {
              // execute the functor:
              m_sc = fun ( obj ) ;
              // in the case of error try use Exception Service
              if ( 0 != svc && m_sc.isFailure() ) { m_sc = svc->handleErr ( *obj , m_sc ) ; }
            }
            catch ( const GaudiException& e )
            {
              // Use the local handler and then (if possible) the Exception Service
              handle ( e  , log ) ;
              if ( 0 != svc ) { m_sc = svc -> handle ( *obj , e ) ; }
            }
            catch ( const std::exception& e )
            {
              // Use the local handler and then (if possible) the Exception Service
              handle ( e  , log ) ;
              if ( 0 != svc ) { m_sc = svc -> handle ( *obj , e ) ; }
            }
            catch ( ...  )
            {
              // Use the local handler and then (if possible) the Exception Service
              handle (      log ) ;
              if ( 0 != svc ) { m_sc = svc -> handle ( *obj     ) ; }
            }
          }

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

destructor

Definition at line 61 of file Guards.cpp.

    { m_sc.ignore() ; }

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.

    { return m_sc   ; }

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

local handler of GaudiException

Definition at line 26 of file Guards.cpp.

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

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.

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

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

local handler of UNKNOWN exceptions

Definition at line 53 of file Guards.cpp.

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

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

cast operator, useful for the implicit conversions

Definition at line 156 of file Guards.h.

    { return code() ; }

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:

- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v22r4/GaudiKernel/GaudiKernel/Guards.h
- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v22r4/GaudiKernel/src/Lib/Guards.cpp

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines