File indexing completed on 2026-08-06 09:38:32
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef ThePEG_Exception_H
0010 #define ThePEG_Exception_H
0011
0012
0013 #include <exception>
0014 #include "ThePEG/Config/ThePEG.h"
0015 #include "Exception.fh"
0016 #include <string>
0017 #include <iosfwd>
0018
0019 extern "C" {
0020 void breakThePEG();
0021 }
0022
0023 namespace ThePEG {
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044 class Exception: public exception {
0045
0046 public:
0047
0048
0049
0050
0051 enum Severity {
0052 unknown,
0053 info,
0054
0055 warning,
0056
0057 setuperror,
0058
0059 eventerror,
0060
0061 runerror,
0062
0063 maybeabort,
0064
0065 abortnow
0066
0067
0068 };
0069
0070 public:
0071
0072
0073
0074
0075
0076
0077 Exception(const string & str, Severity sev);
0078
0079
0080
0081
0082 Exception() : handled(false), theSeverity(unknown) { breakThePEG(); }
0083
0084
0085
0086
0087 Exception(const Exception & ex)
0088 : std::exception(ex), theMessage(ex.message()),
0089 handled(ex.handled), theSeverity(ex.severity())
0090 {
0091 ex.handle();
0092 }
0093
0094
0095
0096
0097 virtual ~Exception() noexcept;
0098
0099 public:
0100
0101
0102
0103
0104 const Exception & operator=(const Exception & ex) {
0105 handled = ex.handled;
0106 theMessage << ex.message();
0107 theSeverity = ex.severity();
0108 ex.handle();
0109 return *this;
0110 }
0111
0112
0113
0114
0115 bool operator==(const Exception & ex) const {
0116 return ( message() == ex.message() && severity() == ex.severity() );
0117 }
0118
0119
0120
0121
0122
0123 bool operator<(const Exception & ex) const {
0124 return ( severity() == ex.severity() ?
0125 ( message() < ex.message() ) :
0126 ( severity() < ex.severity() ) );
0127 }
0128
0129 public:
0130
0131
0132
0133
0134 virtual const char* what() const noexcept {
0135 static string str;
0136 str = message();
0137 return str.c_str();
0138 }
0139
0140
0141
0142
0143 string message() const {
0144 string mess = theMessage.str();
0145 return mess.empty() ? string("Error message not provided.") : mess;
0146 }
0147
0148
0149
0150
0151 void writeMessage(ostream & os = *errstream) const;
0152
0153
0154
0155
0156 Severity severity() const { return theSeverity; }
0157
0158
0159
0160
0161 void handle() const { handled = true; }
0162
0163
0164
0165
0166 template <typename T>
0167 Exception & operator<<(const T & t) {
0168 theMessage << t;
0169 return *this;
0170 }
0171
0172
0173
0174
0175 Exception & operator<<(Severity sev) {
0176 severity(sev);
0177 return *this;
0178 }
0179
0180 protected:
0181
0182
0183
0184
0185 void severity(Severity);
0186
0187
0188
0189
0190 mutable ostringstream theMessage;
0191
0192 private:
0193
0194
0195
0196
0197 mutable bool handled;
0198
0199
0200
0201
0202 Severity theSeverity;
0203
0204
0205
0206
0207 static ostream * errstream;
0208
0209 public:
0210
0211
0212
0213
0214
0215 static bool noabort;
0216
0217 };
0218
0219 }
0220
0221 #endif