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 #if !defined(MYSQLPP_EXCEPTIONS_H)
00032 #define MYSQLPP_EXCEPTIONS_H
00033
00034 #include "options.h"
00035
00036 #include <exception>
00037 #include <string>
00038
00039 namespace mysqlpp {
00040
00042
00043 class MYSQLPP_EXPORT Exception : public std::exception
00044 {
00045 public:
00047 Exception(const Exception& e) throw() :
00048 std::exception(e),
00049 what_(e.what_)
00050 {
00051 }
00052
00054 Exception& operator=(const Exception& rhs) throw()
00055 {
00056 what_ = rhs.what_;
00057 return *this;
00058 }
00059
00061 ~Exception() throw() { }
00062
00064 virtual const char* what() const throw()
00065 {
00066 return what_.c_str();
00067 }
00068
00069 protected:
00071 Exception(const char* w = "") throw() :
00072 what_(w)
00073 {
00074 }
00075
00077 Exception(const std::string& w) throw() :
00078 what_(w)
00079 {
00080 }
00081
00083 std::string what_;
00084 };
00085
00086
00088
00089 class MYSQLPP_EXPORT BadConversion : public Exception
00090 {
00091 public:
00092 const char* type_name;
00093 std::string data;
00094 size_t retrieved;
00095 size_t actual_size;
00096
00104 BadConversion(const char* tn, const char* d,
00105 size_t r, size_t a) :
00106 Exception("Bad type conversion: \""),
00107 type_name(tn),
00108 data(d),
00109 retrieved(r),
00110 actual_size(a)
00111 {
00112 what_ += d ? d : "<NULL>";
00113 what_ += "\" incompatible with \"";
00114 what_ += tn;
00115 what_ += "\" type";
00116 }
00117
00125 BadConversion(const std::string& w, const char* tn,
00126 const char* d, size_t r, size_t a) :
00127 Exception(w),
00128 type_name(tn),
00129 data(d),
00130 retrieved(r),
00131 actual_size(a)
00132 {
00133 }
00134
00140 explicit BadConversion(const char* w = "") :
00141 Exception(w),
00142 type_name("unknown"),
00143 data(""),
00144 retrieved(0),
00145 actual_size(0)
00146 {
00147 }
00148
00150 ~BadConversion() throw() { }
00151 };
00152
00153
00158
00159 class MYSQLPP_EXPORT BadFieldName : public Exception
00160 {
00161 public:
00165 explicit BadFieldName(const char* bad_field) :
00166 Exception(std::string("Unknown field name: ") + bad_field)
00167 {
00168 }
00169
00171 ~BadFieldName() throw() { }
00172 };
00173
00174
00177
00178 class MYSQLPP_EXPORT BadOption : public Exception
00179 {
00180 public:
00182 explicit BadOption(const char* w, const std::type_info& ti) :
00183 Exception(w),
00184 ti_(ti)
00185 {
00186 }
00187
00189 explicit BadOption(const std::string& w, const std::type_info& ti) :
00190 Exception(w),
00191 ti_(ti)
00192 {
00193 }
00194
00199 const std::type_info& what_option() const { return ti_; }
00200
00201 private:
00202 const std::type_info& ti_;
00203 };
00204
00205
00210
00211 class MYSQLPP_EXPORT BadParamCount : public Exception
00212 {
00213 public:
00215 explicit BadParamCount(const char* w = "") :
00216 Exception(w)
00217 {
00218 }
00219
00221 ~BadParamCount() throw() { }
00222 };
00223
00226
00227 class MYSQLPP_EXPORT UseQueryError : public Exception
00228 {
00229 public:
00231 explicit UseQueryError(const char* w = "") :
00232 Exception(w)
00233 {
00234 }
00235 };
00236
00237
00257
00258 class MYSQLPP_EXPORT BadQuery : public Exception
00259 {
00260 public:
00265 explicit BadQuery(const char* w = "", int e = 0) :
00266 Exception(w),
00267 errnum_(e)
00268 {
00269 }
00270
00275 explicit BadQuery(const std::string& w, int e = 0) :
00276 Exception(w),
00277 errnum_(e)
00278 {
00279 }
00280
00287 int errnum() const { return errnum_; }
00288
00289 private:
00290 int errnum_;
00291 };
00292
00293
00300
00301 class MYSQLPP_EXPORT ConnectionFailed : public Exception
00302 {
00303 public:
00308 explicit ConnectionFailed(const char* w = "", int e = 0) :
00309 Exception(w),
00310 errnum_(e)
00311 {
00312 }
00313
00322 int errnum() const { return errnum_; }
00323
00324 private:
00325 int errnum_;
00326 };
00327
00328
00331
00332 class MYSQLPP_EXPORT DBSelectionFailed : public Exception
00333 {
00334 public:
00339 explicit DBSelectionFailed(const char* w = "", int e = 0) :
00340 Exception(w),
00341 errnum_(e)
00342 {
00343 }
00344
00353 int errnum() const { return errnum_; }
00354
00355 private:
00356 int errnum_;
00357 };
00358
00359
00361
00362 class MYSQLPP_EXPORT MutexFailed : public Exception
00363 {
00364 public:
00366 explicit MutexFailed(const char* w = "lock failed") :
00367 Exception(w)
00368 {
00369 }
00370 };
00371
00372
00375
00376 class MYSQLPP_EXPORT ObjectNotInitialized : public Exception
00377 {
00378 public:
00380 explicit ObjectNotInitialized(const char* w = "") :
00381 Exception(w)
00382 {
00383 }
00384 };
00385
00386
00388
00389 class MYSQLPP_EXPORT SelfTestFailed : public Exception
00390 {
00391 public:
00393 explicit SelfTestFailed(const std::string& w) :
00394 Exception(w)
00395 {
00396 }
00397 };
00398
00399
00410
00411 class MYSQLPP_EXPORT TypeLookupFailed : public Exception
00412 {
00413 public:
00415 explicit TypeLookupFailed(const std::string& w) :
00416 Exception(w)
00417 {
00418 }
00419 };
00420
00421
00422 }
00423
00424 #endif // !defined(MYSQLPP_EXCEPTIONS_H)