thepeg is hosted by Hepforge, IPPP Durham
ThePEG  2.2.1
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. More...
 
 ~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. More...
 

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.

Member Function Documentation

◆ operator<<()

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().


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