00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef _PASSENGER_EXCEPTIONS_H_
00019 #define _PASSENGER_EXCEPTIONS_H_
00020
00021 #include <exception>
00022 #include <string>
00023 #include <sstream>
00024
00025
00026
00027
00028
00029 namespace Passenger {
00030
00031 using namespace std;
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 class SystemException: public exception {
00042 private:
00043 string briefMessage;
00044 string systemMessage;
00045 string fullMessage;
00046 int m_code;
00047 public:
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 SystemException(const string &message, int errorCode) {
00061 stringstream str;
00062
00063 briefMessage = message;
00064 str << strerror(errorCode) << " (" << errorCode << ")";
00065 systemMessage = str.str();
00066
00067 fullMessage = briefMessage + ": " + systemMessage;
00068 m_code = errorCode;
00069 }
00070
00071 virtual ~SystemException() throw() {}
00072
00073 virtual const char *what() const throw() {
00074 return fullMessage.c_str();
00075 }
00076
00077
00078
00079
00080 int code() const throw() {
00081 return m_code;
00082 }
00083
00084
00085
00086
00087
00088
00089 string brief() const throw() {
00090 return briefMessage;
00091 }
00092
00093
00094
00095
00096
00097 string sys() const throw() {
00098 return systemMessage;
00099 }
00100 };
00101
00102
00103
00104
00105
00106
00107 class IOException: public exception {
00108 private:
00109 string msg;
00110 public:
00111 IOException(const string &message): msg(message) {}
00112 virtual ~IOException() throw() {}
00113 virtual const char *what() const throw() { return msg.c_str(); }
00114 };
00115
00116
00117
00118
00119 class FileNotFoundException: public IOException {
00120 public:
00121 FileNotFoundException(const string &message): IOException(message) {}
00122 virtual ~FileNotFoundException() throw() {}
00123 };
00124
00125
00126
00127
00128
00129
00130 class SpawnException: public exception {
00131 private:
00132 string msg;
00133 bool m_hasErrorPage;
00134 string m_errorPage;
00135 public:
00136 SpawnException(const string &message)
00137 : msg(message) {
00138 m_hasErrorPage = false;
00139 }
00140
00141 SpawnException(const string &message, const string &errorPage)
00142 : msg(message), m_errorPage(errorPage) {
00143 m_hasErrorPage = true;
00144 }
00145
00146 virtual ~SpawnException() throw() {}
00147 virtual const char *what() const throw() { return msg.c_str(); }
00148
00149
00150
00151
00152 bool hasErrorPage() const {
00153 return m_hasErrorPage;
00154 }
00155
00156
00157
00158
00159
00160
00161 const string getErrorPage() const {
00162 return m_errorPage;
00163 }
00164 };
00165
00166 }
00167
00168 #endif