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
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #ifndef Foundation_Exception_INCLUDED
00040 #define Foundation_Exception_INCLUDED
00041
00042
00043 #include "Poco/Foundation.h"
00044 #include <stdexcept>
00045
00046
00047 namespace Poco {
00048
00049
00050 class Foundation_API Exception: public std::exception
00053 {
00054 public:
00055 Exception(const std::string& msg, int code = 0);
00057
00058 Exception(const std::string& msg, const std::string& arg, int code = 0);
00060
00061 Exception(const std::string& msg, const Exception& nested, int code = 0);
00064
00065 Exception(const Exception& exc);
00067
00068 ~Exception() throw();
00070
00071 Exception& operator = (const Exception& exc);
00073
00074 virtual const char* name() const throw();
00076
00077 virtual const char* className() const throw();
00079
00080 virtual const char* what() const throw();
00084
00085 const Exception* nested() const;
00088
00089 const std::string& message() const;
00091
00092 int code() const;
00094
00095 std::string displayText() const;
00098
00099 virtual Exception* clone() const;
00104
00105 virtual void rethrow() const;
00111
00112 protected:
00113 Exception(int code = 0);
00115
00116 private:
00117 std::string _msg;
00118 Exception* _pNested;
00119 int _code;
00120 };
00121
00122
00123
00124
00125
00126 inline const Exception* Exception::nested() const
00127 {
00128 return _pNested;
00129 }
00130
00131
00132 inline const std::string& Exception::message() const
00133 {
00134 return _msg;
00135 }
00136
00137
00138 inline int Exception::code() const
00139 {
00140 return _code;
00141 }
00142
00143
00144
00145
00146
00147
00148
00149
00150 #define POCO_DECLARE_EXCEPTION(API, CLS, BASE) \
00151 class API CLS: public BASE \
00152 { \
00153 public: \
00154 CLS(int code = 0); \
00155 CLS(const std::string& msg, int code = 0); \
00156 CLS(const std::string& msg, const std::string& arg, int code = 0); \
00157 CLS(const std::string& msg, const Poco::Exception& exc, int code = 0); \
00158 CLS(const CLS& exc); \
00159 ~CLS() throw(); \
00160 CLS& operator = (const CLS& exc); \
00161 const char* name() const throw(); \
00162 const char* className() const throw(); \
00163 Poco::Exception* clone() const; \
00164 void rethrow() const; \
00165 };
00166
00167
00168 #define POCO_IMPLEMENT_EXCEPTION(CLS, BASE, NAME) \
00169 CLS::CLS(int code): BASE(code) \
00170 { \
00171 } \
00172 CLS::CLS(const std::string& msg, int code): BASE(msg, code) \
00173 { \
00174 } \
00175 CLS::CLS(const std::string& msg, const std::string& arg, int code): BASE(msg, arg, code) \
00176 { \
00177 } \
00178 CLS::CLS(const std::string& msg, const Poco::Exception& exc, int code): BASE(msg, exc, code) \
00179 { \
00180 } \
00181 CLS::CLS(const CLS& exc): BASE(exc) \
00182 { \
00183 } \
00184 CLS::~CLS() throw() \
00185 { \
00186 } \
00187 CLS& CLS::operator = (const CLS& exc) \
00188 { \
00189 BASE::operator = (exc); \
00190 return *this; \
00191 } \
00192 const char* CLS::name() const throw() \
00193 { \
00194 return NAME; \
00195 } \
00196 const char* CLS::className() const throw() \
00197 { \
00198 return typeid(*this).name(); \
00199 } \
00200 Poco::Exception* CLS::clone() const \
00201 { \
00202 return new CLS(*this); \
00203 } \
00204 void CLS::rethrow() const \
00205 { \
00206 throw *this; \
00207 }
00208
00209
00210
00211
00212
00213 POCO_DECLARE_EXCEPTION(Foundation_API, LogicException, Exception)
00214 POCO_DECLARE_EXCEPTION(Foundation_API, AssertionViolationException, LogicException)
00215 POCO_DECLARE_EXCEPTION(Foundation_API, NullPointerException, LogicException)
00216 POCO_DECLARE_EXCEPTION(Foundation_API, BugcheckException, LogicException)
00217 POCO_DECLARE_EXCEPTION(Foundation_API, InvalidArgumentException, LogicException)
00218 POCO_DECLARE_EXCEPTION(Foundation_API, NotImplementedException, LogicException)
00219 POCO_DECLARE_EXCEPTION(Foundation_API, RangeException, LogicException)
00220 POCO_DECLARE_EXCEPTION(Foundation_API, IllegalStateException, LogicException)
00221 POCO_DECLARE_EXCEPTION(Foundation_API, InvalidAccessException, LogicException)
00222 POCO_DECLARE_EXCEPTION(Foundation_API, SignalException, LogicException)
00223 POCO_DECLARE_EXCEPTION(Foundation_API, UnhandledException, LogicException)
00224
00225 POCO_DECLARE_EXCEPTION(Foundation_API, RuntimeException, Exception)
00226 POCO_DECLARE_EXCEPTION(Foundation_API, NotFoundException, RuntimeException)
00227 POCO_DECLARE_EXCEPTION(Foundation_API, ExistsException, RuntimeException)
00228 POCO_DECLARE_EXCEPTION(Foundation_API, TimeoutException, RuntimeException)
00229 POCO_DECLARE_EXCEPTION(Foundation_API, SystemException, RuntimeException)
00230 POCO_DECLARE_EXCEPTION(Foundation_API, RegularExpressionException, RuntimeException)
00231 POCO_DECLARE_EXCEPTION(Foundation_API, LibraryLoadException, RuntimeException)
00232 POCO_DECLARE_EXCEPTION(Foundation_API, LibraryAlreadyLoadedException, RuntimeException)
00233 POCO_DECLARE_EXCEPTION(Foundation_API, NoThreadAvailableException, RuntimeException)
00234 POCO_DECLARE_EXCEPTION(Foundation_API, PropertyNotSupportedException, RuntimeException)
00235 POCO_DECLARE_EXCEPTION(Foundation_API, PoolOverflowException, RuntimeException)
00236 POCO_DECLARE_EXCEPTION(Foundation_API, NoPermissionException, RuntimeException)
00237 POCO_DECLARE_EXCEPTION(Foundation_API, OutOfMemoryException, RuntimeException)
00238 POCO_DECLARE_EXCEPTION(Foundation_API, DataException, RuntimeException)
00239
00240 POCO_DECLARE_EXCEPTION(Foundation_API, DataFormatException, DataException)
00241 POCO_DECLARE_EXCEPTION(Foundation_API, SyntaxException, DataException)
00242 POCO_DECLARE_EXCEPTION(Foundation_API, CircularReferenceException, DataException)
00243 POCO_DECLARE_EXCEPTION(Foundation_API, PathSyntaxException, SyntaxException)
00244 POCO_DECLARE_EXCEPTION(Foundation_API, IOException, RuntimeException)
00245 POCO_DECLARE_EXCEPTION(Foundation_API, FileException, IOException)
00246 POCO_DECLARE_EXCEPTION(Foundation_API, FileExistsException, FileException)
00247 POCO_DECLARE_EXCEPTION(Foundation_API, FileNotFoundException, FileException)
00248 POCO_DECLARE_EXCEPTION(Foundation_API, PathNotFoundException, FileException)
00249 POCO_DECLARE_EXCEPTION(Foundation_API, FileReadOnlyException, FileException)
00250 POCO_DECLARE_EXCEPTION(Foundation_API, FileAccessDeniedException, FileException)
00251 POCO_DECLARE_EXCEPTION(Foundation_API, CreateFileException, FileException)
00252 POCO_DECLARE_EXCEPTION(Foundation_API, OpenFileException, FileException)
00253 POCO_DECLARE_EXCEPTION(Foundation_API, WriteFileException, FileException)
00254 POCO_DECLARE_EXCEPTION(Foundation_API, ReadFileException, FileException)
00255 POCO_DECLARE_EXCEPTION(Foundation_API, UnknownURISchemeException, RuntimeException)
00256
00257 POCO_DECLARE_EXCEPTION(Foundation_API, ApplicationException, Exception)
00258 POCO_DECLARE_EXCEPTION(Foundation_API, BadCastException, RuntimeException)
00259
00260
00261 }
00262
00263
00264 #endif // Foundation_Exception_INCLUDED