thepeg is hosted by Hepforge, IPPP Durham
ThePEG 2.3.0
Throw.h
1// -*- C++ -*-
2//
3// Throw.h is a part of ThePEG - Toolkit for HEP Event Generation
4// Copyright (C) 1999-2019 Leif Lonnblad
5//
6// ThePEG is licenced under version 3 of the GPL, see COPYING for details.
7// Please respect the MCnet academic guidelines, see GUIDELINES for details.
8//
9#ifndef ThePEG_Throw_H
10#define ThePEG_Throw_H
11// This is the declaration of the Throw class.
12
14#include "ThePEG/Utilities/Exception.h"
15#include "ThePEG/Repository/CurrentGenerator.h"
16#include "ThePEG/Repository/Repository.h"
17
18
19namespace ThePEG {
43template <typename Ex>
44struct Throw {
45public:
49 Throw(): ex(Ex()), handled(false) {}
50
54 template <typename T> Throw & operator<<(const T & t) {
55 ex << t;
56 return *this;
57 }
58
59private:
65 void writeWarning() {
67 Repository::clog() << ex.message() << endl;
68 ex.handle();
69 } else {
71 }
72 }
73
74public:
82 handled = true;
83 ex << sev;
84 if ( sev != Exception::warning && sev != Exception::info ) {
85 throw ex;
86 } else {
88 }
89 }
90
95 if ( !handled ) {
98 }
99 }
100
104 Ex ex;
105
111};
112
113
114}
115
116#endif /* ThePEG_Throw_H */
This is the main config header file for ThePEG.
static ostream & clog()
Get the standard log stream.
static bool isVoid()
Returns true if there is no currently chosen EventGenerator object.
static EventGenerator & current()
Return a reference to the currently chosen EventGenerator object.
void logWarning(const Exception &)
Log a given exception.
Severity
The levels of severity.
Definition: Exception.h:51
@ warning
Possibly severe, (the user should be warned).
Definition: Exception.h:55
@ info
Not severe (but the user should be informed).
Definition: Exception.h:53
This is the main namespace within which all identifiers in ThePEG are declared.
Definition: FactoryBase.h:28
Helper function to make it easier to throw exceptions.
Definition: Throw.h:44
void operator<<(Exception::Severity sev)
Specify the Exception::Severity of the exception.
Definition: Throw.h:81
Ex ex
The ExceptionObject to be thrown.
Definition: Throw.h:104
bool handled
If true, the exception has been handled and should not be thrown in the destructor.
Definition: Throw.h:110
~Throw()
The destructor will throw the exception if it has not been handled.
Definition: Throw.h:94
Throw()
Standard constructor creating an internal Exception object.
Definition: Throw.h:49
Throw & operator<<(const T &t)
Add information to the current Exception object.
Definition: Throw.h:54
void writeWarning()
Write warning messages to the current EventGenerator.
Definition: Throw.h:65