00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef _PASSENGER_EXCEPTIONS_H_
00026 #define _PASSENGER_EXCEPTIONS_H_
00027
00028 #include <oxt/tracable_exception.hpp>
00029 #include <string>
00030 #include <sstream>
00031 #include <cstring>
00032
00033
00034
00035
00036
00037 namespace Passenger {
00038
00039 using namespace std;
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049 class SystemException: public oxt::tracable_exception {
00050 private:
00051 string briefMessage;
00052 string systemMessage;
00053 string fullMessage;
00054 int m_code;
00055 public:
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068 SystemException(const string &briefMessage, int errorCode) {
00069 stringstream str;
00070
00071 str << strerror(errorCode) << " (" << errorCode << ")";
00072 systemMessage = str.str();
00073
00074 setBriefMessage(briefMessage);
00075 m_code = errorCode;
00076 }
00077
00078 virtual ~SystemException() throw() {}
00079
00080 virtual const char *what() const throw() {
00081 return fullMessage.c_str();
00082 }
00083
00084 void setBriefMessage(const string &message) {
00085 briefMessage = message;
00086 fullMessage = briefMessage + ": " + systemMessage;
00087 }
00088
00089
00090
00091
00092 int code() const throw() {
00093 return m_code;
00094 }
00095
00096
00097
00098
00099
00100
00101 string brief() const throw() {
00102 return briefMessage;
00103 }
00104
00105
00106
00107
00108
00109 string sys() const throw() {
00110 return systemMessage;
00111 }
00112 };
00113
00114
00115
00116
00117
00118
00119
00120 class FileSystemException: public SystemException {
00121 private:
00122 string m_filename;
00123 public:
00124 FileSystemException(const string &message, int errorCode,
00125 const string &filename)
00126 : SystemException(message, errorCode),
00127 m_filename(filename) {}
00128
00129 virtual ~FileSystemException() throw() {}
00130
00131
00132
00133
00134 string filename() const throw() {
00135 return m_filename;
00136 }
00137 };
00138
00139
00140
00141
00142
00143
00144 class TimeRetrievalException: public SystemException {
00145 public:
00146 TimeRetrievalException(const string &message, int errorCode)
00147 : SystemException(message, errorCode)
00148 {}
00149 virtual ~TimeRetrievalException() throw() {}
00150 };
00151
00152
00153
00154
00155
00156
00157 class IOException: public oxt::tracable_exception {
00158 private:
00159 string msg;
00160 public:
00161 IOException(const string &message): msg(message) {}
00162 virtual ~IOException() throw() {}
00163 virtual const char *what() const throw() { return msg.c_str(); }
00164 };
00165
00166
00167
00168
00169 class FileNotFoundException: public IOException {
00170 public:
00171 FileNotFoundException(const string &message): IOException(message) {}
00172 virtual ~FileNotFoundException() throw() {}
00173 };
00174
00175
00176
00177
00178
00179
00180 class EOFException: public IOException {
00181 public:
00182 EOFException(const string &message): IOException(message) {}
00183 virtual ~EOFException() throw() {}
00184 };
00185
00186
00187
00188
00189 class ConfigurationException: public oxt::tracable_exception {
00190 private:
00191 string msg;
00192 public:
00193 ConfigurationException(const string &message): msg(message) {}
00194 virtual ~ConfigurationException() throw() {}
00195 virtual const char *what() const throw() { return msg.c_str(); }
00196 };
00197
00198
00199
00200
00201
00202
00203 class SpawnException: public oxt::tracable_exception {
00204 private:
00205 string msg;
00206 bool m_hasErrorPage;
00207 bool m_isHTML;
00208 string m_errorPage;
00209 public:
00210 SpawnException(const string &message)
00211 : msg(message) {
00212 m_hasErrorPage = false;
00213 m_isHTML = false;
00214 }
00215
00216 SpawnException(const string &message, const string &errorPage, bool isHTML = true)
00217 : msg(message), m_errorPage(errorPage)
00218 {
00219 m_hasErrorPage = true;
00220 m_isHTML = isHTML;
00221 }
00222
00223 virtual ~SpawnException() throw() {}
00224 virtual const char *what() const throw() { return msg.c_str(); }
00225
00226
00227
00228
00229 bool hasErrorPage() const {
00230 return m_hasErrorPage;
00231 }
00232
00233
00234
00235
00236
00237
00238 const string getErrorPage() const {
00239 return m_errorPage;
00240 }
00241
00242
00243
00244
00245
00246
00247 bool isHTML() const {
00248 return m_isHTML;
00249 }
00250 };
00251
00252
00253
00254
00255
00256
00257 class ArgumentException: public oxt::tracable_exception {
00258 private:
00259 string msg;
00260 public:
00261 ArgumentException(const string &message): msg(message) {}
00262 virtual ~ArgumentException() throw() {}
00263 virtual const char *what() const throw() { return msg.c_str(); }
00264 };
00265
00266
00267
00268
00269 class InvalidModeStringException: public ArgumentException {
00270 public:
00271 InvalidModeStringException(const string &message): ArgumentException(message) {}
00272 };
00273
00274
00275
00276
00277
00278
00279 class RuntimeException: public oxt::tracable_exception {
00280 private:
00281 string msg;
00282 public:
00283 RuntimeException(const string &message): msg(message) {}
00284 virtual ~RuntimeException() throw() {}
00285 virtual const char *what() const throw() { return msg.c_str(); }
00286 };
00287
00288
00289
00290
00291
00292
00293 class TimeoutException: public oxt::tracable_exception {
00294 private:
00295 string msg;
00296 public:
00297 TimeoutException(const string &message): msg(message) {}
00298 virtual ~TimeoutException() throw() {}
00299 virtual const char *what() const throw() { return msg.c_str(); }
00300 };
00301
00302
00303
00304
00305
00306
00307 class SecurityException: public oxt::tracable_exception {
00308 private:
00309 string msg;
00310 public:
00311 SecurityException(const string &message): msg(message) {}
00312 virtual ~SecurityException() throw() {}
00313 virtual const char *what() const throw() { return msg.c_str(); }
00314 };
00315
00316
00317
00318
00319 class NonExistentUserException: public SecurityException {
00320 public:
00321 NonExistentUserException(const string &message): SecurityException(message) {}
00322 };
00323
00324
00325
00326
00327 class NonExistentGroupException: public SecurityException {
00328 public:
00329 NonExistentGroupException(const string &message): SecurityException(message) {}
00330 };
00331
00332
00333
00334
00335
00336
00337 class BusyException: public oxt::tracable_exception {
00338 private:
00339 string msg;
00340 public:
00341 BusyException(const string &message): msg(message) {}
00342 virtual ~BusyException() throw() {}
00343 virtual const char *what() const throw() { return msg.c_str(); }
00344 };
00345
00346
00347
00348
00349
00350
00351 class SyntaxError: public oxt::tracable_exception {
00352 private:
00353 string msg;
00354 public:
00355 SyntaxError(const string &message): msg(message) {}
00356 virtual ~SyntaxError() throw() {}
00357 virtual const char *what() const throw() { return msg.c_str(); }
00358 };
00359
00360 }
00361
00362 #endif