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 <oxt/tracable_exception.hpp>
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 oxt::tracable_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 &briefMessage, int errorCode) {
00064 stringstream str;
00065
00066 str << strerror(errorCode) << " (" << errorCode << ")";
00067 systemMessage = str.str();
00068
00069 setBriefMessage(briefMessage);
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 void setBriefMessage(const string &message) {
00080 briefMessage = message;
00081 fullMessage = briefMessage + ": " + systemMessage;
00082 }
00083
00084
00085
00086
00087 int code() const throw() {
00088 return m_code;
00089 }
00090
00091
00092
00093
00094
00095
00096 string brief() const throw() {
00097 return briefMessage;
00098 }
00099
00100
00101
00102
00103
00104 string sys() const throw() {
00105 return systemMessage;
00106 }
00107 };
00108
00109
00110
00111
00112
00113
00114
00115 class FileSystemException: public SystemException {
00116 private:
00117 string m_filename;
00118 public:
00119 FileSystemException(const string &message, int errorCode,
00120 const string &filename)
00121 : SystemException(message, errorCode),
00122 m_filename(filename) {}
00123
00124 virtual ~FileSystemException() throw() {}
00125
00126
00127
00128
00129 string filename() const throw() {
00130 return m_filename;
00131 }
00132 };
00133
00134
00135
00136
00137
00138
00139 class IOException: public oxt::tracable_exception {
00140 private:
00141 string msg;
00142 public:
00143 IOException(const string &message): msg(message) {}
00144 virtual ~IOException() throw() {}
00145 virtual const char *what() const throw() { return msg.c_str(); }
00146 };
00147
00148
00149
00150
00151 class FileNotFoundException: public IOException {
00152 public:
00153 FileNotFoundException(const string &message): IOException(message) {}
00154 virtual ~FileNotFoundException() throw() {}
00155 };
00156
00157
00158
00159
00160 class ConfigurationException: public oxt::tracable_exception {
00161 private:
00162 string msg;
00163 public:
00164 ConfigurationException(const string &message): msg(message) {}
00165 virtual ~ConfigurationException() throw() {}
00166 virtual const char *what() const throw() { return msg.c_str(); }
00167 };
00168
00169
00170
00171
00172
00173
00174 class SpawnException: public oxt::tracable_exception {
00175 private:
00176 string msg;
00177 bool m_hasErrorPage;
00178 string m_errorPage;
00179 public:
00180 SpawnException(const string &message)
00181 : msg(message) {
00182 m_hasErrorPage = false;
00183 }
00184
00185 SpawnException(const string &message, const string &errorPage)
00186 : msg(message), m_errorPage(errorPage) {
00187 m_hasErrorPage = true;
00188 }
00189
00190 virtual ~SpawnException() throw() {}
00191 virtual const char *what() const throw() { return msg.c_str(); }
00192
00193
00194
00195
00196 bool hasErrorPage() const {
00197 return m_hasErrorPage;
00198 }
00199
00200
00201
00202
00203
00204
00205 const string getErrorPage() const {
00206 return m_errorPage;
00207 }
00208 };
00209
00210
00211
00212
00213
00214
00215 class RuntimeException: public oxt::tracable_exception {
00216 private:
00217 string msg;
00218 public:
00219 RuntimeException(const string &message): msg(message) {}
00220 virtual ~RuntimeException() throw() {}
00221 virtual const char *what() const throw() { return msg.c_str(); }
00222 };
00223
00224
00225
00226
00227
00228
00229 class BusyException: public oxt::tracable_exception {
00230 private:
00231 string msg;
00232 public:
00233 BusyException(const string &message): msg(message) {}
00234 virtual ~BusyException() throw() {}
00235 virtual const char *what() const throw() { return msg.c_str(); }
00236 };
00237
00238 }
00239
00240 #endif