Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class 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 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 BadNullConversion : public Exception
00179 {
00180 public:
00182         explicit BadNullConversion(const char* w = "") :
00183         Exception(w)
00184         {
00185         }
00186 };
00187 
00188 
00191 
00192 class MYSQLPP_EXPORT BadOption : public Exception
00193 {
00194 public:
00196         explicit BadOption(const char* w,
00197                         Connection::Option o) :
00198         Exception(w),
00199         option_(o)
00200         {
00201         }
00202 
00204         explicit BadOption(const std::string& w,
00205                         Connection::Option o) :
00206         Exception(w),
00207         option_(o)
00208         {
00209         }
00210 
00212         Connection::Option what_option() const { return option_; }
00213 
00214 private:
00215         Connection::Option option_;
00216 };
00217 
00218 
00223 
00224 class MYSQLPP_EXPORT BadParamCount : public Exception
00225 {
00226 public:
00228         explicit BadParamCount(const char* w = "") :
00229         Exception(w)
00230         {
00231         }
00232 
00234         ~BadParamCount() throw() { }
00235 };
00236 
00237 
00244 
00245 class MYSQLPP_EXPORT BadQuery : public Exception
00246 {
00247 public:
00249         explicit BadQuery(const char* w = "") :
00250         Exception(w)
00251         {
00252         }
00253 
00255         explicit BadQuery(const std::string& w) :
00256         Exception(w)
00257         {
00258         }
00259 };
00260 
00261 
00265 
00266 class MYSQLPP_EXPORT ConnectionFailed : public Exception
00267 {
00268 public:
00270         explicit ConnectionFailed(const char* w = "") :
00271         Exception(w)
00272         {
00273         }
00274 };
00275 
00276 
00279 
00280 class MYSQLPP_EXPORT DBSelectionFailed : public Exception
00281 {
00282 public:
00284         explicit DBSelectionFailed(const char* w = "") :
00285         Exception(w)
00286         {
00287         }
00288 };
00289 
00290 
00293 
00294 class MYSQLPP_EXPORT EndOfResults : public Exception
00295 {
00296 public:
00298         explicit EndOfResults(const char* w = "end of results") :
00299         Exception(w)
00300         {
00301         }
00302 };
00303 
00304 
00307 
00308 class MYSQLPP_EXPORT EndOfResultSets : public Exception
00309 {
00310 public:
00312         explicit EndOfResultSets(const char* w = "end of result sets") :
00313         Exception(w)
00314         {
00315         }
00316 };
00317 
00318 
00326 
00327 class MYSQLPP_EXPORT LockFailed : public Exception
00328 {
00329 public:
00331         explicit LockFailed(const char* w = "lock failed") :
00332         Exception(w)
00333         {
00334         }
00335 };
00336 
00337 
00340 
00341 class MYSQLPP_EXPORT ObjectNotInitialized : public Exception
00342 {
00343 public:
00345         explicit ObjectNotInitialized(const char* w = "") :
00346         Exception(w)
00347         {
00348         }
00349 };
00350 
00351 
00352 } // end namespace mysqlpp
00353 
00354 #endif

Generated on Wed Jul 11 15:34:34 2007 for MySQL++ by doxygen 1.3.5