thepeg is hosted by Hepforge, IPPP Durham
ThePEG 2.3.0
ThePEG::Throw< Ex > Struct Template Reference

Helper function to make it easier to throw exceptions. More...

#include <Throw.h>

Public Member Functions

 Throw ()
 Standard constructor creating an internal Exception object.
 
template<typename T >
Throwoperator<< (const T &t)
 Add information to the current Exception object.
 
void operator<< (Exception::Severity sev)
 Specify the Exception::Severity of the exception.
 
 ~Throw ()
 The destructor will throw the exception if it has not been handled.
 

Public Attributes

Ex ex
 The ExceptionObject to be thrown.
 
bool handled
 If true, the exception has been handled and should not be thrown in the destructor.
 

Private Member Functions

void writeWarning ()
 Write warning messages to the current EventGenerator.
 

Detailed Description

template<typename Ex>
struct ThePEG::Throw< Ex >

Helper function to make it easier to throw exceptions.

The template argument should be a class inheriting from Exception. In the constructor, an object of this Exception class is created and afterwards a message may be added using ostream-like output (<<). If a Exception::Severity value is output with << the Exception object is assumed to be complete and the exception is actually thrown, except if the Exception::Severity value Exception::warning was specified, in which case the Exception object is treated as a warning which is logged with the current EventGenerator. If no current EventGenerator is present the warning message is instead written to std::cerr. If no Exception::Severity is specified, the Exception object is treated as a warning when the Throw object is destroyed.

Assuming you have an Exception class called MyEx the Throw class is used as follows:
Throw<MyEx&gt>() << "My error message" << Exception::eventerror;
This will throw an exception and the current event will be discarded. Changing Exception::eventerror to Exception::warning will write out a warning, but no proper exception is thrown.

Definition at line 44 of file Throw.h.

Constructor & Destructor Documentation

◆ Throw()

template<typename Ex >
ThePEG::Throw< Ex >::Throw ( )
inline

Standard constructor creating an internal Exception object.

Definition at line 49 of file Throw.h.

◆ ~Throw()

template<typename Ex >
ThePEG::Throw< Ex >::~Throw ( )
inline

The destructor will throw the exception if it has not been handled.

Definition at line 94 of file Throw.h.

References ThePEG::Throw< Ex >::ex, ThePEG::Throw< Ex >::handled, ThePEG::Exception::warning, and ThePEG::Throw< Ex >::writeWarning().

Member Function Documentation

◆ operator<<() [1/2]

template<typename Ex >
template<typename T >
Throw & ThePEG::Throw< Ex >::operator<< ( const T &  t)
inline

Add information to the current Exception object.

Definition at line 54 of file Throw.h.

References ThePEG::Throw< Ex >::ex.

◆ operator<<() [2/2]

template<typename Ex >
void ThePEG::Throw< Ex >::operator<< ( Exception::Severity  sev)
inline

Specify the Exception::Severity of the exception.

If this is Exception::warning, the exception will not be thown, instead it will be logged with writeWarning(). All other seveities will cause the exception to be thrown immediately.

Definition at line 81 of file Throw.h.

References ThePEG::Throw< Ex >::ex, ThePEG::Throw< Ex >::handled, ThePEG::Exception::info, ThePEG::Exception::warning, and ThePEG::Throw< Ex >::writeWarning().

◆ writeWarning()

template<typename Ex >
void ThePEG::Throw< Ex >::writeWarning ( )
inlineprivate

Write warning messages to the current EventGenerator.

If no current EventGenerator is present, the warning message is instead written to std::cerr.

Definition at line 65 of file Throw.h.

References ThePEG::BaseRepository::clog(), ThePEG::CurrentGenerator::current(), ThePEG::Throw< Ex >::ex, ThePEG::CurrentGenerator::isVoid(), and ThePEG::EventGenerator::logWarning().

Referenced by ThePEG::Throw< Ex >::operator<<(), and ThePEG::Throw< Ex >::~Throw().

Member Data Documentation

◆ ex

template<typename Ex >
Ex ThePEG::Throw< Ex >::ex

The ExceptionObject to be thrown.

Definition at line 104 of file Throw.h.

Referenced by ThePEG::Throw< Ex >::operator<<(), ThePEG::Throw< Ex >::writeWarning(), and ThePEG::Throw< Ex >::~Throw().

◆ handled

template<typename Ex >
bool ThePEG::Throw< Ex >::handled

If true, the exception has been handled and should not be thrown in the destructor.

Definition at line 110 of file Throw.h.

Referenced by ThePEG::Throw< Ex >::operator<<(), and ThePEG::Throw< Ex >::~Throw().


The documentation for this struct was generated from the following file: