# exceptions.h

Go to the documentation of this file.

    00001
    00002
    00003
    00004
    00005
    00006
    00007 /***********************************************************************
    00008  Copyright (c) 1998 by Kevin Atkinson, (c) 1999-2001 by MySQL AB, and
    00009  (c) 2004-2007 by Educational Technology Resources, Inc.  Others may
    00010  also hold copyrights on code in this file.  See the CREDITS.txt file
    00011  in the top directory of the distribution for details.
    00012
    00013  This file is part of MySQL++.
    00014
    00015  MySQL++ is free software; you can redistribute it and/or modify it
    00016  under the terms of the GNU Lesser General Public License as published
    00017  by the Free Software Foundation; either version 2.1 of the License, or
    00018  (at your option) any later version.
    00019
    00020  MySQL++ is distributed in the hope that it will be useful, but WITHOUT
    00021  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    00022  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
    00023  License for more details.
    00024
    00025  You should have received a copy of the GNU Lesser General Public
    00026  License along with MySQL++; if not, write to the Free Software
    00027  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
    00028  USA
    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 #include <sstream>
    00039
    00040 namespace mysqlpp {
    00041
    00043
    00044 class MYSQLPP_EXPORT Exception : public std::exception
    00045 {
    00046 public:
    00048         Exception(const Exception& e) throw() :
    00049         std::exception(e),
    00050         what_(e.what_)
    00051         {
    00052         }
    00053
    00055         Exception& operator=(const Exception& rhs) throw()
    00056         {
    00057                 what_ = rhs.what_;
    00058                 return *this;
    00059         }
    00060
    00062         ~Exception() throw() { }
    00063
    00065         virtual const char* what() const throw()
    00066         {
    00067                 return what_.c_str();
    00068         }
    00069
    00070 protected:
    00072         Exception(const char* w = "") throw() :
    00073         what_(w)
    00074         {
    00075         }
    00076
    00078         Exception(const std::string& w) throw() :
    00079         what_(w)
    00080         {
    00081         }
    00082
    00084         std::string what_;
    00085 };
    00086
    00087
    00089
    00090 class MYSQLPP_EXPORT BadConversion : public Exception
    00091 {
    00092 public:
    00093         const char* type_name;
    00094         std::string data;
    00095         size_t retrieved;
    00096         size_t actual_size;
    00097
    00105         BadConversion(const char* tn, const char* d,
    00106                         size_t r, size_t a) :
    00107         Exception("Bad type conversion: \""),
    00108         type_name(tn),
    00109         data(d),
    00110         retrieved(r),
    00111         actual_size(a)
    00112         {
    00113                 what_ += d ? d : "<NULL>";
    00114                 what_ += "\" incompatible with \"";
    00115                 what_ += tn;
    00116                 what_ += "\" type";
    00117         }
    00118
    00126         BadConversion(const std::string& w, const char* tn,
    00127                                   const char* d, size_t r, size_t a) :
    00128         Exception(w),
    00129         type_name(tn),
    00130         data(d),
    00131         retrieved(r),
    00132         actual_size(a)
    00133         {
    00134         }
    00135
    00141         explicit BadConversion(const char* w = "") :
    00142         Exception(w),
    00143         type_name("unknown"),
    00144         data(""),
    00145         retrieved(0),
    00146         actual_size(0)
    00147         {
    00148         }
    00149
    00151         ~BadConversion() throw() { }
    00152 };
    00153
    00154
    00159
    00160 class MYSQLPP_EXPORT BadFieldName : public Exception
    00161 {
    00162 public:
    00166         explicit BadFieldName(const char* bad_field) :
    00167         Exception(std::string("Unknown field name: ") + bad_field)
    00168         {
    00169         }
    00170
    00172         ~BadFieldName() throw() { }
    00173 };
    00174
    00175
    00178
    00179 class MYSQLPP_EXPORT BadIndex : public Exception
    00180 {
    00181 public:
    00187         explicit BadIndex(const char* what, int bad_index, int max_index) :
    00188         Exception()
    00189         {
    00190                 std::ostringstream outs;
    00191                 outs << "Index " << bad_index << " on " << what <<
    00192                                 " out of range, max legal index is " << max_index;
    00193                 what_ = outs.str();
    00194         }
    00195
    00197         ~BadIndex() throw() { }
    00198 };
    00199
    00200
    00203
    00204 class MYSQLPP_EXPORT BadOption : public Exception
    00205 {
    00206 public:
    00208         explicit BadOption(const char* w, const std::type_info& ti) :
    00209         Exception(w),
    00210         ti_(ti)
    00211         {
    00212         }
    00213
    00215         explicit BadOption(const std::string& w, const std::type_info& ti) :
    00216         Exception(w),
    00217         ti_(ti)
    00218         {
    00219         }
    00220
    00225         const std::type_info& what_option() const { return ti_; }
    00226
    00227 private:
    00228         const std::type_info& ti_;
    00229 };
    00230
    00231
    00236
    00237 class MYSQLPP_EXPORT BadParamCount : public Exception
    00238 {
    00239 public:
    00241         explicit BadParamCount(const char* w = "") :
    00242         Exception(w)
    00243         {
    00244         }
    00245
    00247         ~BadParamCount() throw() { }
    00248 };
    00249
    00252
    00253 class MYSQLPP_EXPORT UseQueryError : public Exception
    00254 {
    00255 public:
    00257         explicit UseQueryError(const char* w = "") :
    00258         Exception(w)
    00259         {
    00260         }
    00261 };
    00262
    00263
    00283
    00284 class MYSQLPP_EXPORT BadQuery : public Exception
    00285 {
    00286 public:
    00291         explicit BadQuery(const char* w = "", int e = 0) :
    00292         Exception(w),
    00293         errnum_(e)
    00294         {
    00295         }
    00296
    00301         explicit BadQuery(const std::string& w, int e = 0) :
    00302         Exception(w),
    00303         errnum_(e)
    00304         {
    00305         }
    00306
    00313         int errnum() const { return errnum_; }
    00314
    00315 private:
    00316         int     errnum_;
    00317 };
    00318
    00319
    00326
    00327 class MYSQLPP_EXPORT ConnectionFailed : public Exception
    00328 {
    00329 public:
    00334         explicit ConnectionFailed(const char* w = "", int e = 0) :
    00335         Exception(w),
    00336         errnum_(e)
    00337         {
    00338         }
    00339
    00348         int errnum() const { return errnum_; }
    00349
    00350 private:
    00351         int     errnum_;
    00352 };
    00353
    00354
    00357
    00358 class MYSQLPP_EXPORT DBSelectionFailed : public Exception
    00359 {
    00360 public:
    00365         explicit DBSelectionFailed(const char* w = "", int e = 0) :
    00366         Exception(w),
    00367         errnum_(e)
    00368         {
    00369         }
    00370
    00379         int errnum() const { return errnum_; }
    00380
    00381 private:
    00382         int     errnum_;
    00383 };
    00384
    00385
    00387
    00388 class MYSQLPP_EXPORT MutexFailed : public Exception
    00389 {
    00390 public:
    00392         explicit MutexFailed(const char* w = "lock failed") :
    00393         Exception(w)
    00394         {
    00395         }
    00396 };
    00397
    00398
    00401
    00402 class MYSQLPP_EXPORT ObjectNotInitialized : public Exception
    00403 {
    00404 public:
    00406         explicit ObjectNotInitialized(const char* w = "") :
    00407         Exception(w)
    00408         {
    00409         }
    00410 };
    00411
    00412
    00414
    00415 class MYSQLPP_EXPORT SelfTestFailed : public Exception
    00416 {
    00417 public:
    00419         explicit SelfTestFailed(const std::string& w) :
    00420         Exception(w)
    00421         {
    00422         }
    00423 };
    00424
    00425
    00436
    00437 class MYSQLPP_EXPORT TypeLookupFailed : public Exception
    00438 {
    00439 public:
    00441         explicit TypeLookupFailed(const std::string& w) :
    00442         Exception(w)
    00443         {
    00444         }
    00445 };
    00446
    00447
    00448 } // end namespace mysqlpp
    00449
    00450 #endif // !defined(MYSQLPP_EXCEPTIONS_H)