Main Page Namespace List Class Hierarchy Compound List File List Namespace Members Compound Members 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, 2000 and 2001 by
    00009  MySQL AB, and (c) 2004, 2005 by Educational Technology Resources, Inc.
    00010  Others may also hold copyrights on code in this file.  See the CREDITS
    00011  file 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 #ifndef MYSQLPP_EXCEPTIONS_H
    00032 #define MYSQLPP_EXCEPTIONS_H
    00033
    00034 #include "connection.h"
    00035
    00036 #include <exception>
    00037 #include <string>
    00038
    00039 namespace mysqlpp {
    00040
    00042
    00043 class 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 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(std::string("Tried to convert \"") +
    00107                         std::string(d ? d : "") + "\" to a \"" +
    00108                         std::string(tn ? tn : "")),
    00109         type_name(tn),
    00110         data(d),
    00111         retrieved(r),
    00112         actual_size(a)
    00113         {
    00114         }
    00115
    00123         BadConversion(const std::string& w, const char* tn,
    00124                                   const char* d, size_t r, size_t a) :
    00125         Exception(w),
    00126         type_name(tn),
    00127         data(d),
    00128         retrieved(r),
    00129         actual_size(a)
    00130         {
    00131         }
    00132
    00138         explicit BadConversion(const char* w = "") :
    00139         Exception(w),
    00140         type_name("unknown"),
    00141         data(""),
    00142         retrieved(0),
    00143         actual_size(0)
    00144         {
    00145         }
    00146
    00148         ~BadConversion() throw() { }
    00149 };
    00150
    00151
    00156
    00157 class BadFieldName : public Exception
    00158 {
    00159 public:
    00163         explicit BadFieldName(const char* bad_field) :
    00164         Exception(std::string("Unknown field name: ") + bad_field)
    00165         {
    00166         }
    00167
    00169         ~BadFieldName() throw() { }
    00170 };
    00171
    00172
    00175
    00176 class BadNullConversion : public Exception
    00177 {
    00178 public:
    00180         explicit BadNullConversion(const char* w = "") :
    00181         Exception(w)
    00182         {
    00183         }
    00184 };
    00185
    00186
    00189
    00190 class BadOption : public Exception
    00191 {
    00192 public:
    00194         explicit BadOption(const char* w,
    00195                         Connection::Option o) :
    00196         Exception(w),
    00197         option_(o)
    00198         {
    00199         }
    00200
    00202         explicit BadOption(const std::string& w,
    00203                         Connection::Option o) :
    00204         Exception(w),
    00205         option_(o)
    00206         {
    00207         }
    00208
    00210         Connection::Option what_option() const { return option_; }
    00211
    00212 private:
    00213         Connection::Option option_;
    00214 };
    00215
    00216
    00221
    00222 class BadParamCount : public Exception
    00223 {
    00224 public:
    00226         explicit BadParamCount(const char* w = "") :
    00227         Exception(w)
    00228         {
    00229         }
    00230
    00232         ~BadParamCount() throw() { }
    00233 };
    00234
    00235
    00242
    00243 class BadQuery : public Exception
    00244 {
    00245 public:
    00247         explicit BadQuery(const char* w = "") :
    00248         Exception(w)
    00249         {
    00250         }
    00251
    00253         explicit BadQuery(const std::string& w) :
    00254         Exception(w)
    00255         {
    00256         }
    00257 };
    00258
    00259
    00263
    00264 class ConnectionFailed : public Exception
    00265 {
    00266 public:
    00268         explicit ConnectionFailed(const char* w = "") :
    00269         Exception(w)
    00270         {
    00271         }
    00272 };
    00273
    00274
    00277
    00278 class DBSelectionFailed : public Exception
    00279 {
    00280 public:
    00282         explicit DBSelectionFailed(const char* w = "") :
    00283         Exception(w)
    00284         {
    00285         }
    00286 };
    00287
    00288
    00291
    00292 class EndOfResults : public Exception
    00293 {
    00294 public:
    00296         explicit EndOfResults(const char* w = "end of results") :
    00297         Exception(w)
    00298         {
    00299         }
    00300 };
    00301
    00302
    00305
    00306 class EndOfResultSets : public Exception
    00307 {
    00308 public:
    00310         explicit EndOfResultSets(const char* w = "end of result sets") :
    00311         Exception(w)
    00312         {
    00313         }
    00314 };
    00315
    00316
    00324
    00325 class LockFailed : public Exception
    00326 {
    00327 public:
    00329         explicit LockFailed(const char* w = "lock failed") :
    00330         Exception(w)
    00331         {
    00332         }
    00333 };
    00334
    00335
    00338
    00339 class ObjectNotInitialized : public Exception
    00340 {
    00341 public:
    00343         explicit ObjectNotInitialized(const char* w = "") :
    00344         Exception(w)
    00345         {
    00346         }
    00347 };
    00348
    00349
    00350 } // end namespace mysqlpp
    00351
    00352 #endif