00001 // -*- C++ -*- 00002 // 00003 // Throw.h is a part of ThePEG - Toolkit for HEP Event Generation 00004 // Copyright (C) 1999-2007 Leif Lonnblad 00005 // 00006 // ThePEG is licenced under version 2 of the GPL, see COPYING for details. 00007 // Please respect the MCnet academic guidelines, see GUIDELINES for details. 00008 // 00009 #ifndef ThePEG_Throw_H 00010 #define ThePEG_Throw_H 00011 // This is the declaration of the Throw class. 00012 00013 #include "ThePEG/Config/ThePEG.h" 00014 #include "ThePEG/Utilities/Exception.h" 00015 #include "ThePEG/Repository/CurrentGenerator.h" 00016 #include "ThePEG/Repository/Repository.h" 00017 00018 00019 namespace ThePEG { 00043 template <typename Ex> 00044 struct Throw { 00045 00049 Throw(): ex(Ex()), handled(false) {} 00050 00054 template <typename T> Throw & operator<<(const T & t) { 00055 ex << t; 00056 return *this; 00057 } 00058 00067 void operator<<(Exception::Severity sev) { 00068 handled = true; 00069 ex << sev; 00070 if ( sev != Exception::warning && sev != Exception::info ) { 00071 throw ex; 00072 } else { 00073 if ( CurrentGenerator::isVoid() ) { 00074 Repository::clog() << ex.message() << endl; 00075 ex.handle(); 00076 } else { 00077 CurrentGenerator::current().logWarning(ex); 00078 } 00079 } 00080 } 00081 00085 ~Throw() { 00086 if ( !handled ) throw ex; 00087 } 00088 00092 Ex ex; 00093 00098 bool handled; 00099 }; 00100 00101 00102 } 00103 00104 #endif /* ThePEG_Throw_H */