00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _PASSENGER_EXCEPTIONS_H_
00021 #define _PASSENGER_EXCEPTIONS_H_
00022
00023 #include <exception>
00024 #include <string>
00025 #include <sstream>
00026 #include <cstring>
00027
00028
00029
00030
00031
00032 namespace Passenger {
00033
00034 using namespace std;
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 class SystemException: public exception {
00045 private:
00046 string briefMessage;
00047 string systemMessage;
00048 string fullMessage;
00049 int m_code;
00050 public:
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063 SystemException(const string &message, int errorCode) {
00064 stringstream str;
00065
00066 briefMessage = message;
00067 str << strerror(errorCode) << " (" << errorCode << ")";
00068 systemMessage = str.str();
00069
00070 fullMessage = briefMessage + ": " + systemMessage;
00071 m_code = errorCode;
00072 }
00073
00074 virtual ~SystemException() throw() {}
00075
00076 virtual const char *what() const throw() {
00077 return fullMessage.c_str();
00078 }
00079
00080
00081
00082
00083 int code() const throw() {
00084 return m_code;
00085 }
00086
00087
00088
00089
00090
00091
00092 string brief() const throw() {
00093 return briefMessage;
00094 }
00095
00096
00097
00098
00099
00100 string sys() const throw() {
00101 return systemMessage;
00102 }
00103 };
00104
00105
00106
00107
00108
00109
00110
00111 class FileSystemException: public SystemException {
00112 private:
00113 string m_filename;
00114 public:
00115 FileSystemException(const string &message, int errorCode,
00116 const string &filename)
00117 : SystemException(message, errorCode),
00118 m_filename(filename) {}
00119
00120 virtual ~FileSystemException() throw() {}
00121
00122
00123
00124
00125 string filename() const throw() {
00126 return m_filename;
00127 }
00128 };
00129
00130
00131
00132
00133
00134
00135 class IOException: public exception {
00136 private:
00137 string msg;
00138 public:
00139 IOException(const string &message): msg(message) {}
00140 virtual ~IOException() throw() {}
00141 virtual const char *what() const throw() { return msg.c_str(); }
00142 };
00143
00144
00145
00146
00147 class FileNotFoundException: public IOException {
00148 public:
00149 FileNotFoundException(const string &message): IOException(message) {}
00150 virtual ~FileNotFoundException() throw() {}
00151 };
00152
00153
00154
00155
00156 class ConfigurationException: public exception {
00157 private:
00158 string msg;
00159 public:
00160 ConfigurationException(const string &message): msg(message) {}
00161 virtual ~ConfigurationException() throw() {}
00162 virtual const char *what() const throw() { return msg.c_str(); }
00163 };
00164
00165
00166
00167
00168
00169
00170 class SpawnException: public exception {
00171 private:
00172 string msg;
00173 bool m_hasErrorPage;
00174 string m_errorPage;
00175 public:
00176 SpawnException(const string &message)
00177 : msg(message) {
00178 m_hasErrorPage = false;
00179 }
00180
00181 SpawnException(const string &message, const string &errorPage)
00182 : msg(message), m_errorPage(errorPage) {
00183 m_hasErrorPage = true;
00184 }
00185
00186 virtual ~SpawnException() throw() {}
00187 virtual const char *what() const throw() { return msg.c_str(); }
00188
00189
00190
00191
00192 bool hasErrorPage() const {
00193 return m_hasErrorPage;
00194 }
00195
00196
00197
00198
00199
00200
00201 const string getErrorPage() const {
00202 return m_errorPage;
00203 }
00204 };
00205
00206
00207
00208
00209
00210
00211 class BusyException: public exception {
00212 private:
00213 string msg;
00214 public:
00215 BusyException(const string &message): msg(message) {}
00216 virtual ~BusyException() throw() {}
00217 virtual const char *what() const throw() { return msg.c_str(); }
00218 };
00219
00220 }
00221
00222 #endif