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 */