| # Gaudi Framework, version v20r2
Generated: 18 Jul 2008

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

- Search for |

- Alphabetical List
- Class List
- Class Hierarchy
- Class Members

# Gaudi::Guards::ExceptionGuard Class Reference

`#include <GaudiKernel/Guards.h>`

Collaboration diagram for Gaudi::Guards::ExceptionGuard:

[legend]
List of all members.

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

## 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 implict 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::xception
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

## Constructor & Destructor Documentation

template<class OBJECT, class FUNCTION>

Gaudi::Guards::ExceptionGuard::ExceptionGuard | ( | OBJECT | obj,
|  | FUNCTION | fun,
|  | MsgStream & | log,
|  | IExceptionSvc * | svc = `0` |
| ) |  |  | `[inline]`

Definition at line 118 of file Guards.h.

References handle(), StatusCode::isFailure(), and m_sc.

    00122         : m_sc  ( StatusCode::FAILURE )
    00123       {
    00124         try
    00125         {
    00126           // execute the functor:
    00127           m_sc = fun ( obj ) ;
    00128           // in the case of error try use Exception Service
    00129           if ( 0 != svc && m_sc.isFailure() ) { m_sc = svc->handleErr ( *obj , m_sc ) ; }
    00130         }
    00131         catch ( const GaudiException& e )
    00132         {
    00133           // Use the local handler and then (if possible) the Exception Service
    00134           handle ( e  , log ) ;
    00135           if ( 0 != svc ) { m_sc = svc -> handle ( *obj , e ) ; }
    00136         }
    00137         catch ( const std::exception& e )
    00138         {
    00139           // Use the local handler and then (if possible) the Exception Service
    00140           handle ( e  , log ) ;
    00141           if ( 0 != svc ) { m_sc = svc -> handle ( *obj , e ) ; }
    00142         }
    00143         catch ( ...  )
    00144         {
    00145           // Use the local handler and then (if possible) the Exception Service
    00146           handle (      log ) ;
    00147           if ( 0 != svc ) { m_sc = svc -> handle ( *obj     ) ; }
    00148         }
    00149       }

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

destructor

Definition at line 97 of file Guards.cpp.

References StatusCode::ignore(), and m_sc.

    00097 { 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.

References m_sc.

Referenced by operator const StatusCode &().

    00154 { return m_sc   ; }

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

cast operator, useful for the implict conversions

Definition at line 156 of file Guards.h.

References code().

    00156 { return code() ; }

ExceptionGuard& Gaudi::Guards::ExceptionGuard::operator= | ( | const ExceptionGuard & |  | ) | `[private]`

no assignement

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

local handler of GaudiException

Definition at line 62 of file Guards.cpp.

References endreq(), MSG::ERROR, MSG::FATAL, and System::typeinfoName().

Referenced by ExceptionGuard().

    00063 {
    00064   // the general printout
    00065   log << MSG::FATAL
    00066       << System::typeinfoName( typeid ( exc ) )
    00067       << "('" << exc.tag() << "') is caught!" << endreq ;
    00068   // print the detailes about the exception:
    00069   log << MSG::ERROR << exc << endreq ;
    00070   // get the status code form the exception:
    00071   m_sc = exc.code() ;
    00072 }

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

local handler of std::xception

Definition at line 77 of file Guards.cpp.

References endreq(), MSG::ERROR, MSG::FATAL, and System::typeinfoName().

    00078 {
    00079   // the general printout
    00080   log << MSG::FATAL
    00081       << System::typeinfoName( typeid ( exc ) ) << " is caught!" << endreq ;
    00082   // print the detailes abotu the exception:
    00083   log << MSG::ERROR << exc.what() << endreq ;
    00084 }

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

local handler of UNKNOWN exceptions

Definition at line 89 of file Guards.cpp.

References endreq(), and MSG::FATAL.

    00090 {
    00091   // the general printout
    00092   log << MSG::FATAL << "UNKNOWN exception is caught!" << endreq ;
    00093 }

## Member Data Documentation

StatusCode Gaudi::Guards::ExceptionGuard::m_sc`[private]`

status code : result of function evaluation

Definition at line 173 of file Guards.h.

Referenced by code(), ExceptionGuard(), and ~ExceptionGuard().

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

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