thepeg is hosted by Hepforge, IPPP Durham
ThePEG  2.2.1
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 
13 #include "ThePEG/Config/ThePEG.h"
14 #include "ThePEG/Utilities/Exception.h"
15 #include "ThePEG/Repository/CurrentGenerator.h"
16 #include "ThePEG/Repository/Repository.h"
17 
18 
19 namespace ThePEG {
43 template <typename Ex>
44 struct Throw {
45 public:
49  Throw(): ex(Ex()), handled(false) {}
50 
54  template <typename T> Throw & operator<<(const T & t) {
55  ex << t;
56  return *this;
57  }
58 
59 private:
65  void writeWarning() {
66  if ( CurrentGenerator::isVoid() ) {
67  Repository::clog() << ex.message() << endl;
68  ex.handle();
69  } else {
71  }
72  }
73 
74 public:
82  handled = true;
83  ex << sev;
84  if ( sev != Exception::warning && sev != Exception::info ) {
85  throw ex;
86  } else {
87  writeWarning();
88  }
89  }
90 
94  ~Throw() {
95  if ( !handled ) {
97  writeWarning();
98  }
99  }
100 
104  Ex ex;
105 
110  bool handled;
111 };
112 
113 
114 }
115 
116 #endif /* ThePEG_Throw_H */
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
This is the main config header file for ThePEG.
void logWarning(const Exception &)
Log a given exception.
static ostream & clog()
Get the standard log stream.
~Throw()
The destructor will throw the exception if it has not been handled.
Definition: Throw.h:94
Ex ex
The ExceptionObject to be thrown.
Definition: Throw.h:104
Not severe (but the user should be informed).
Definition: Exception.h:53
bool handled
If true, the exception has been handled and should not be thrown in the destructor.
Definition: Throw.h:110
Severity
The levels of severity.
Definition: Exception.h:51
static EventGenerator & current()
Return a reference to the currently chosen EventGenerator object.
void writeWarning()
Write warning messages to the current EventGenerator.
Definition: Throw.h:65
Possibly severe, (the user should be warned).
Definition: Exception.h:55
static bool isVoid()
Returns true if there is no currently chosen EventGenerator object.
Throw & operator<<(const T &t)
Add information to the current Exception object.
Definition: Throw.h:54
Throw()
Standard constructor creating an internal Exception object.
Definition: Throw.h:49
void operator<<(Exception::Severity sev)
Specify the Exception::Severity of the exception.
Definition: Throw.h:81