/usr/include/ThePEG/Utilities/Throw.h is in libthepeg-dev 1.8.0-1.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | // -*- C++ -*-
//
// Throw.h is a part of ThePEG - Toolkit for HEP Event Generation
// Copyright (C) 1999-2011 Leif Lonnblad
//
// ThePEG is licenced under version 2 of the GPL, see COPYING for details.
// Please respect the MCnet academic guidelines, see GUIDELINES for details.
//
#ifndef ThePEG_Throw_H
#define ThePEG_Throw_H
// This is the declaration of the Throw class.
#include "ThePEG/Config/ThePEG.h"
#include "ThePEG/Utilities/Exception.h"
#include "ThePEG/Repository/CurrentGenerator.h"
#include "ThePEG/Repository/Repository.h"
namespace ThePEG {
/**
* Helper function to make it easier to throw exceptions. The template
* argument should be a class inheriting from Exception. In the
* constructor, an object of this Exception class is created and
* afterwards a message may be added using ostream-like output
* (<<). If a Exception::Severity value is output with <<
* the Exception object is assumed to be complete and the exception is
* actually thrown, except if the Exception::Severity value
* Exception::warning was specified, in which case the Exception
* object is treated as a warning which is logged with the current
* EventGenerator. If no current EventGenerator is present the warning
* message is instead written to std::cerr. If no Exception::Severity
* is specified, the Exception object is thrown when the Throw object
* is destroyed.
*
* Assuming you have an Exception class called MyEx the Throw class is
* used as follows:<br><code>Throw<MyEx>>() << "My error
* message" << Exception::eventerror;</code><br> This will throw
* an exception and the current event will be discarded. Changing
* <code>Exception::eventerror</code> to
* <code>Exception::warning</code> will write out a warning, but no
* proper exception is thrown.
*/
template <typename Ex>
struct Throw {
/**
* Standard constructor creating an internal Exception object.
*/
Throw(): ex(Ex()), handled(false) {}
/**
* Add information to the current Exception object.
*/
template <typename T> Throw & operator<<(const T & t) {
ex << t;
return *this;
}
/**
* Specify the Exception::Severity of the exception. If this is
* Exception::warning, the exception will not be thown, instead it
* will be logged with the current * EventGenerator. If no current
* EventGenerator is present the warning * message is instead
* written to std::cerr. All other seveities will cause the
* exception to be thrown immediately.
*/
void operator<<(Exception::Severity sev) {
handled = true;
ex << sev;
if ( sev != Exception::warning && sev != Exception::info ) {
throw ex;
} else {
if ( CurrentGenerator::isVoid() ) {
Repository::clog() << ex.message() << endl;
ex.handle();
} else {
CurrentGenerator::current().logWarning(ex);
}
}
}
/**
* The destructor will throw the exception if it has not been handled.
*/
~Throw() {
if ( !handled ) throw ex;
}
/**
* The ExceptionObject to be thrown.
*/
Ex ex;
/**
* If true, the exception has been handled and should not be thrown
* in the destructor.
*/
bool handled;
};
}
#endif /* ThePEG_Throw_H */
|