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