- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

# 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-2010 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 #include <typeinfo>
    00040
    00041 namespace mysqlpp {
    00042
    00044
    00045 class MYSQLPP_EXPORT Exception : public std::exception
    00046 {
    00047 public:
    00049         Exception(const Exception& e) throw() :
    00050         std::exception(e),
    00051         what_(e.what_)
    00052         {
    00053         }
    00054
    00056         Exception& operator=(const Exception& rhs) throw()
    00057         {
    00058                 what_ = rhs.what_;
    00059                 return *this;
    00060         }
    00061
    00063         ~Exception() throw() { }
    00064
    00066         virtual const char* what() const throw()
    00067         {
    00068                 return what_.c_str();
    00069         }
    00070
    00071 protected:
    00073         Exception(const char* w = "") throw() :
    00074         what_(w)
    00075         {
    00076         }
    00077
    00079         Exception(const std::string& w) throw() :
    00080         what_(w)
    00081         {
    00082         }
    00083
    00085         std::string what_;
    00086 };
    00087
    00088
    00090
    00091 class MYSQLPP_EXPORT BadConversion : public Exception
    00092 {
    00093 public:
    00094         const char* type_name;
    00095         std::string data;
    00096         size_t retrieved;
    00097         size_t actual_size;
    00098
    00106         BadConversion(const char* tn, const char* d,
    00107                         size_t r, size_t a) :
    00108         Exception("Bad type conversion: \""),
    00109         type_name(tn),
    00110         data(d),
    00111         retrieved(r),
    00112         actual_size(a)
    00113         {
    00114                 what_ += d ? d : "<NULL>";
    00115                 what_ += "\" incompatible with \"";
    00116                 what_ += tn;
    00117                 what_ += "\" type";
    00118         }
    00119
    00127         BadConversion(const std::string& w, const char* tn,
    00128                                   const char* d, size_t r, size_t a) :
    00129         Exception(w),
    00130         type_name(tn),
    00131         data(d),
    00132         retrieved(r),
    00133         actual_size(a)
    00134         {
    00135         }
    00136
    00142         explicit BadConversion(const char* w = "") :
    00143         Exception(w),
    00144         type_name("unknown"),
    00145         data(""),
    00146         retrieved(0),
    00147         actual_size(0)
    00148         {
    00149         }
    00150
    00152         ~BadConversion() throw() { }
    00153 };
    00154
    00155
    00160
    00161 class MYSQLPP_EXPORT BadFieldName : public Exception
    00162 {
    00163 public:
    00167         explicit BadFieldName(const char* bad_field) :
    00168         Exception(std::string("Unknown field name: ") + bad_field)
    00169         {
    00170         }
    00171
    00173         ~BadFieldName() throw() { }
    00174 };
    00175
    00176
    00179
    00180 class MYSQLPP_EXPORT BadIndex : public Exception
    00181 {
    00182 public:
    00188         explicit BadIndex(const char* what, int bad_index, int max_index) :
    00189         Exception()
    00190         {
    00191                 std::ostringstream outs;
    00192                 outs << "Index " << bad_index << " on " << what <<
    00193                                 " out of range, max legal index is " << max_index;
    00194                 what_ = outs.str();
    00195         }
    00196
    00198         ~BadIndex() throw() { }
    00199 };
    00200
    00201
    00204
    00205 class MYSQLPP_EXPORT BadOption : public Exception
    00206 {
    00207 public:
    00209         explicit BadOption(const char* w, const std::type_info& ti) :
    00210         Exception(w),
    00211         ti_(ti)
    00212         {
    00213         }
    00214
    00216         explicit BadOption(const std::string& w, const std::type_info& ti) :
    00217         Exception(w),
    00218         ti_(ti)
    00219         {
    00220         }
    00221
    00226         const std::type_info& what_option() const { return ti_; }
    00227
    00228 private:
    00229         const std::type_info& ti_;
    00230 };
    00231
    00232
    00237
    00238 class MYSQLPP_EXPORT BadParamCount : public Exception
    00239 {
    00240 public:
    00242         explicit BadParamCount(const char* w = "") :
    00243         Exception(w)
    00244         {
    00245         }
    00246
    00248         ~BadParamCount() throw() { }
    00249 };
    00250
    00253
    00254 class MYSQLPP_EXPORT UseQueryError : public Exception
    00255 {
    00256 public:
    00258         explicit UseQueryError(const char* w = "") :
    00259         Exception(w)
    00260         {
    00261         }
    00262 };
    00263
    00264
    00284
    00285 class MYSQLPP_EXPORT BadQuery : public Exception
    00286 {
    00287 public:
    00292         explicit BadQuery(const char* w = "", int e = 0) :
    00293         Exception(w),
    00294         errnum_(e)
    00295         {
    00296         }
    00297
    00302         explicit BadQuery(const std::string& w, int e = 0) :
    00303         Exception(w),
    00304         errnum_(e)
    00305         {
    00306         }
    00307
    00314         int errnum() const { return errnum_; }
    00315
    00316 private:
    00317         int     errnum_;
    00318 };
    00319
    00320
    00327
    00328 class MYSQLPP_EXPORT ConnectionFailed : public Exception
    00329 {
    00330 public:
    00335         explicit ConnectionFailed(const char* w = "", int e = 0) :
    00336         Exception(w),
    00337         errnum_(e)
    00338         {
    00339         }
    00340
    00349         int errnum() const { return errnum_; }
    00350
    00351 private:
    00352         int     errnum_;
    00353 };
    00354
    00355
    00358
    00359 class MYSQLPP_EXPORT DBSelectionFailed : public Exception
    00360 {
    00361 public:
    00366         explicit DBSelectionFailed(const char* w = "", int e = 0) :
    00367         Exception(w),
    00368         errnum_(e)
    00369         {
    00370         }
    00371
    00380         int errnum() const { return errnum_; }
    00381
    00382 private:
    00383         int     errnum_;
    00384 };
    00385
    00386
    00388
    00389 class MYSQLPP_EXPORT MutexFailed : public Exception
    00390 {
    00391 public:
    00393         explicit MutexFailed(const char* w = "lock failed") :
    00394         Exception(w)
    00395         {
    00396         }
    00397 };
    00398
    00399
    00402
    00403 class MYSQLPP_EXPORT ObjectNotInitialized : public Exception
    00404 {
    00405 public:
    00407         explicit ObjectNotInitialized(const char* w = "") :
    00408         Exception(w)
    00409         {
    00410         }
    00411 };
    00412
    00413
    00415
    00416 class MYSQLPP_EXPORT SelfTestFailed : public Exception
    00417 {
    00418 public:
    00420         explicit SelfTestFailed(const std::string& w) :
    00421         Exception(w)
    00422         {
    00423         }
    00424 };
    00425
    00426
    00437
    00438 class MYSQLPP_EXPORT TypeLookupFailed : public Exception
    00439 {
    00440 public:
    00442         explicit TypeLookupFailed(const std::string& w) :
    00443         Exception(w)
    00444         {
    00445         }
    00446 };
    00447
    00448
    00455
    00456 class MYSQLPP_EXPORT BadInsertPolicy : public Exception
    00457 {
    00458 public:
    00460         explicit BadInsertPolicy(const std::string& w) :
    00461         Exception(w)
    00462         {
    00463         }
    00464 };
    00465
    00466
    00467 } // end namespace mysqlpp
    00468
    00469 #endif // !defined(MYSQLPP_EXCEPTIONS_H)