00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef ThePEG_Exception_H
00010 #define ThePEG_Exception_H
00011
00012
00013 #include <exception>
00014 #include "ThePEG/Config/ThePEG.h"
00015 #include "Exception.fh"
00016 #include <string>
00017 #include <iosfwd>
00018
00019 extern "C" {
00020 void breakThePEG();
00021 }
00022
00023 namespace ThePEG {
00024
00044 class Exception: public exception {
00045
00046 public:
00047
00051 enum Severity {
00052 unknown,
00053 info,
00055 warning,
00057 setuperror,
00059 eventerror,
00061 runerror,
00063 maybeabort,
00065 abortnow
00068 };
00069
00070 public:
00071
00077 Exception(const string & str, Severity sev);
00078
00082 Exception() : handled(false), theSeverity(unknown) { breakThePEG(); }
00083
00087 Exception(const Exception & ex)
00088 : std::exception(ex), theMessage(ex.message()),
00089 handled(ex.handled), theSeverity(ex.severity())
00090 {
00091 ex.handle();
00092 }
00093
00097 virtual ~Exception() throw();
00098
00099 public:
00100
00104 const Exception & operator=(const Exception & ex) {
00105 handled = ex.handled;
00106 theMessage << ex.message();
00107 theSeverity = ex.severity();
00108 ex.handle();
00109 return *this;
00110 }
00111
00115 bool operator==(const Exception & ex) const {
00116 return ( message() == ex.message() && severity() == ex.severity() );
00117 }
00118
00123 bool operator<(const Exception & ex) const {
00124 return ( severity() == ex.severity() ?
00125 ( message() < ex.message() ) :
00126 ( severity() < ex.severity() ) );
00127 }
00128
00129 public:
00130
00134 virtual const char* what() const throw() {
00135 return message().c_str();
00136 }
00137
00141 string message() const {
00142 string mess = theMessage.str();
00143 return mess.empty() ? string("Error message not provided.") : mess;
00144 }
00145
00149 void writeMessage(ostream & os = *errstream) const;
00150
00154 Severity severity() const { return theSeverity; }
00155
00159 void handle() const { handled = true; }
00160
00164 template <typename T>
00165 Exception & operator<<(const T & t) {
00166 theMessage << t;
00167 return *this;
00168 }
00169
00173 Exception & operator<<(Severity sev) {
00174 severity(sev);
00175 return *this;
00176 }
00177
00178 protected:
00179
00183 void severity(Severity);
00184
00188 mutable ostringstream theMessage;
00189
00190 private:
00191
00195 mutable bool handled;
00196
00200 Severity theSeverity;
00201
00205 static ostream * errstream;
00206
00207 };
00208
00209 }
00210
00211 #endif