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 string m_errorPage;
00208 public:
00209 SpawnException(const string &message)
00210 : msg(message) {
00211 m_hasErrorPage = false;
00212 }
00213
00214 SpawnException(const string &message, const string &errorPage)
00215 : msg(message), m_errorPage(errorPage) {
00216 m_hasErrorPage = true;
00217 }
00218
00219 virtual ~SpawnException() throw() {}
00220 virtual const char *what() const throw() { return msg.c_str(); }
00221
00222
00223
00224
00225 bool hasErrorPage() const {
00226 return m_hasErrorPage;
00227 }
00228
00229
00230
00231
00232
00233
00234 const string getErrorPage() const {
00235 return m_errorPage;
00236 }
00237 };
00238
00239
00240
00241
00242
00243
00244 class ArgumentException: public oxt::tracable_exception {
00245 private:
00246 string msg;
00247 public:
00248 ArgumentException(const string &message): msg(message) {}
00249 virtual ~ArgumentException() throw() {}
00250 virtual const char *what() const throw() { return msg.c_str(); }
00251 };
00252
00253
00254
00255
00256 class InvalidModeStringException: public ArgumentException {
00257 public:
00258 InvalidModeStringException(const string &message): ArgumentException(message) {}
00259 };
00260
00261
00262
00263
00264
00265
00266 class RuntimeException: public oxt::tracable_exception {
00267 private:
00268 string msg;
00269 public:
00270 RuntimeException(const string &message): msg(message) {}
00271 virtual ~RuntimeException() throw() {}
00272 virtual const char *what() const throw() { return msg.c_str(); }
00273 };
00274
00275
00276
00277
00278
00279
00280 class TimeoutException: public oxt::tracable_exception {
00281 private:
00282 string msg;
00283 public:
00284 TimeoutException(const string &message): msg(message) {}
00285 virtual ~TimeoutException() throw() {}
00286 virtual const char *what() const throw() { return msg.c_str(); }
00287 };
00288
00289
00290
00291
00292
00293
00294 class SecurityException: public oxt::tracable_exception {
00295 private:
00296 string msg;
00297 public:
00298 SecurityException(const string &message): msg(message) {}
00299 virtual ~SecurityException() throw() {}
00300 virtual const char *what() const throw() { return msg.c_str(); }
00301 };
00302
00303
00304
00305
00306 class NonExistentUserException: public SecurityException {
00307 public:
00308 NonExistentUserException(const string &message): SecurityException(message) {}
00309 };
00310
00311
00312
00313
00314 class NonExistentGroupException: public SecurityException {
00315 public:
00316 NonExistentGroupException(const string &message): SecurityException(message) {}
00317 };
00318
00319
00320
00321
00322
00323
00324 class BusyException: public oxt::tracable_exception {
00325 private:
00326 string msg;
00327 public:
00328 BusyException(const string &message): msg(message) {}
00329 virtual ~BusyException() throw() {}
00330 virtual const char *what() const throw() { return msg.c_str(); }
00331 };
00332
00333 }
00334
00335 #endif