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 > | |
Throw & | operator<< (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. | |
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>>() << "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.
|
inline |
|
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().
|
inline |
Add information to the current Exception object.
Definition at line 54 of file Throw.h.
References ThePEG::Throw< Ex >::ex.
|
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().
|
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().
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().
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().