ThePEG  1.8.0
Throw.h
1 // -*- C++ -*-
2 //
3 // Throw.h is a part of ThePEG - Toolkit for HEP Event Generation
4 // Copyright (C) 1999-2011 Leif Lonnblad
5 //
6 // ThePEG is licenced under version 2 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 
49  Throw(): ex(Ex()), handled(false) {}
50 
54  template <typename T> Throw & operator<<(const T & t) {
55  ex << t;
56  return *this;
57  }
58 
68  handled = true;
69  ex << sev;
70  if ( sev != Exception::warning && sev != Exception::info ) {
71  throw ex;
72  } else {
73  if ( CurrentGenerator::isVoid() ) {
74  Repository::clog() << ex.message() << endl;
75  ex.handle();
76  } else {
78  }
79  }
80  }
81 
85  ~Throw() {
86  if ( !handled ) throw ex;
87  }
88 
92  Ex ex;
93 
98  bool handled;
99 };
100 
101 
102 }
103 
104 #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
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:85
Ex ex
The ExceptionObject to be thrown.
Definition: Throw.h:92
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:98
Severity
The levels of severity.
Definition: Exception.h:51
static EventGenerator & current()
Return a reference to the currently chosen EventGenerator object.
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:67