MySQL++: exceptions.h Source File
exceptions.h
Go to the documentation of this file.
/***********************************************************************
Copyright © 1998 by Kevin Atkinson, © 1999-2001 by MySQL AB, and
© 2004-2010, 2018 by Educational Technology Resources, Inc. Others may
also hold copyrights on code in this file. See the CREDITS.txt file
in the top directory of the distribution for details.
This file is part of MySQL++.
MySQL++ is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
MySQL++ is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public
License along with MySQL++; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
USA
***********************************************************************/
#if !defined(MYSQLPP_EXCEPTIONS_H)
#define MYSQLPP_EXCEPTIONS_H
#include "options.h"
#include <exception>
#include <string>
#include <sstream>
#include <typeinfo>
namespace mysqlpp {
class MYSQLPP_EXPORT Exception : public std::exception
{
public:
Exception(const Exception& e) MAY_THROW() :
std::exception(e),
what_(e.what_)
{
}
Exception& operator=(const Exception& rhs) throw()
{
what_ = rhs.what_;
return *this;
}
~Exception() throw() { }
virtual const char* what() const throw()
{
return what_.c_str();
}
protected:
Exception(const char* w = "") throw() :
what_(w)
{
}
Exception(const std::string& w) throw() :
what_(w)
{
}
std::string what_;
};
class MYSQLPP_EXPORT BadConversion : public Exception
{
public:
const char* type_name;
std::string data;
size_t retrieved;
size_t actual_size;
BadConversion(const char* tn, const char* d,
size_t r, size_t a) :
Exception("Bad type conversion: \""),
type_name(tn),
data(d),
retrieved(r),
actual_size(a)
{
what_ += d ? d : "<NULL>";
what_ += "\" incompatible with \"";
what_ += tn;
what_ += "\" type";
}
BadConversion(const std::string& w, const char* tn,
const char* d, size_t r, size_t a) :
Exception(w),
type_name(tn),
data(d),
retrieved(r),
actual_size(a)
{
}
explicit BadConversion(const char* w = "") :
Exception(w),
type_name("unknown"),
data(""),
retrieved(0),
actual_size(0)
{
}
~BadConversion() throw() { }
};
class MYSQLPP_EXPORT BadFieldName : public Exception
{
public:
explicit BadFieldName(const char* bad_field) :
Exception(std::string("Unknown field name: ") + bad_field)
{
}
~BadFieldName() throw() { }
};
class MYSQLPP_EXPORT BadIndex : public Exception
{
public:
explicit BadIndex(const char* what, int bad_index, int max_index) :
Exception()
{
std::ostringstream outs;
outs << "Index " << bad_index << " on " << what <<
" out of range, max legal index is " << max_index;
what_ = outs.str();
}
~BadIndex() throw() { }
};
class MYSQLPP_EXPORT BadOption : public Exception
{
public:
explicit BadOption(const char* w, const std::type_info& ti) :
Exception(w),
ti_(ti)
{
}
explicit BadOption(const std::string& w, const std::type_info& ti) :
Exception(w),
ti_(ti)
{
}
const std::type_info& what_option() const { return ti_; }
private:
const std::type_info& ti_;
};
class MYSQLPP_EXPORT BadParamCount : public Exception
{
public:
explicit BadParamCount(const char* w = "") :
Exception(w)
{
}
~BadParamCount() throw() { }
};
class MYSQLPP_EXPORT UseQueryError : public Exception
{
public:
explicit UseQueryError(const char* w = "") :
Exception(w)
{
}
};
class MYSQLPP_EXPORT BadQuery : public Exception
{
public:
explicit BadQuery(const char* w = "", int e = 0) :
Exception(w),
errnum_(e)
{
}
explicit BadQuery(const std::string& w, int e = 0) :
Exception(w),
errnum_(e)
{
}
int errnum() const { return errnum_; }
private:
int errnum_;
};
class MYSQLPP_EXPORT ConnectionFailed : public Exception
{
public:
explicit ConnectionFailed(const char* w = "", int e = 0) :
Exception(w),
errnum_(e)
{
}
int errnum() const { return errnum_; }
private:
int errnum_;
};
class MYSQLPP_EXPORT DBSelectionFailed : public Exception
{
public:
explicit DBSelectionFailed(const char* w = "", int e = 0) :
Exception(w),
errnum_(e)
{
}
int errnum() const { return errnum_; }
private:
int errnum_;
};
class MYSQLPP_EXPORT MutexFailed : public Exception
{
public:
explicit MutexFailed(const char* w = "lock failed") :
Exception(w)
{
}
};
class MYSQLPP_EXPORT ObjectNotInitialized : public Exception
{
public:
explicit ObjectNotInitialized(const char* w = "") :
Exception(w)
{
}
};
class MYSQLPP_EXPORT SelfTestFailed : public Exception
{
public:
explicit SelfTestFailed(const std::string& w) :
Exception(w)
{
}
};
class MYSQLPP_EXPORT TypeLookupFailed : public Exception
{
public:
explicit TypeLookupFailed(const std::string& w) :
Exception(w)
{
}
};
class MYSQLPP_EXPORT BadInsertPolicy : public Exception
{
public:
explicit BadInsertPolicy(const std::string& w) :
Exception(w)
{
}
};
} // end namespace mysqlpp
#endif // !defined(MYSQLPP_EXCEPTIONS_H)
mysqlpp::BadConversion
Exception thrown when a bad type conversion is attempted.
Definition: exceptions.h:92
mysqlpp::BadConversion::BadConversion
BadConversion(const char *w="")
Create exception object, with error string only.
Definition: exceptions.h:142
mysqlpp::BadConversion::data
std::string data
string form of data we tried to convert
Definition: exceptions.h:95
mysqlpp::BadConversion::actual_size
size_t actual_size
documentation needed!
Definition: exceptions.h:97
mysqlpp::BadConversion::~BadConversion
~BadConversion()
Destroy exception.
Definition: exceptions.h:152
mysqlpp::BadConversion::BadConversion
BadConversion(const char *tn, const char *d, size_t r, size_t a)
Create exception object, building error string dynamically.
Definition: exceptions.h:106
mysqlpp::BadConversion::type_name
const char * type_name
name of type we tried to convert to
Definition: exceptions.h:94
mysqlpp::BadConversion::BadConversion
BadConversion(const std::string &w, const char *tn, const char *d, size_t r, size_t a)
Create exception object, given completed error string.
Definition: exceptions.h:127
mysqlpp::BadConversion::retrieved
size_t retrieved
documentation needed!
Definition: exceptions.h:96
mysqlpp::BadFieldName
Exception thrown when a requested named field doesn't exist.
Definition: exceptions.h:162
mysqlpp::BadFieldName::~BadFieldName
~BadFieldName()
Destroy exception.
Definition: exceptions.h:173
mysqlpp::BadFieldName::BadFieldName
BadFieldName(const char *bad_field)
Create exception object.
Definition: exceptions.h:167
mysqlpp::BadIndex
Exception thrown when an object with operator [] or an at() method gets called with a bad index.
Definition: exceptions.h:181
mysqlpp::BadIndex::BadIndex
BadIndex(const char *what, int bad_index, int max_index)
Create exception object.
Definition: exceptions.h:188
mysqlpp::BadIndex::~BadIndex
~BadIndex()
Destroy exception.
Definition: exceptions.h:198
mysqlpp::BadInsertPolicy
Exception thrown when an insert policy is too strict to create a valid INSERT statement.
Definition: exceptions.h:457
mysqlpp::BadInsertPolicy::BadInsertPolicy
BadInsertPolicy(const std::string &w)
Create exception object.
Definition: exceptions.h:460
mysqlpp::BadOption
Exception thrown when you pass an unrecognized option to Connection::set_option().
Definition: exceptions.h:206
mysqlpp::BadOption::BadOption
BadOption(const std::string &w, const std::type_info &ti)
Create exception object, taking C++ string.
Definition: exceptions.h:216
mysqlpp::BadOption::what_option
const std::type_info & what_option() const
Return type information about the option that failed.
Definition: exceptions.h:226
mysqlpp::BadOption::BadOption
BadOption(const char *w, const std::type_info &ti)
Create exception object, taking C string.
Definition: exceptions.h:209
mysqlpp::BadParamCount
Exception thrown when not enough query parameters are provided.
Definition: exceptions.h:239
mysqlpp::BadParamCount::~BadParamCount
~BadParamCount()
Destroy exception.
Definition: exceptions.h:248
mysqlpp::BadParamCount::BadParamCount
BadParamCount(const char *w="")
Create exception object.
Definition: exceptions.h:242
mysqlpp::BadQuery
Exception thrown when the database server encounters a problem while processing your query.
Definition: exceptions.h:286
mysqlpp::BadQuery::BadQuery
BadQuery(const std::string &w, int e=0)
Create exception object.
Definition: exceptions.h:302
mysqlpp::BadQuery::BadQuery
BadQuery(const char *w="", int e=0)
Create exception object.
Definition: exceptions.h:292
mysqlpp::BadQuery::errnum
int errnum() const
Return the error number corresponding to the error message returned by what()
Definition: exceptions.h:314
mysqlpp::ConnectionFailed
Exception thrown when there is a problem related to the database server connection.
Definition: exceptions.h:329
mysqlpp::ConnectionFailed::errnum
int errnum() const
Return the error number corresponding to the error message returned by what(), if any.
Definition: exceptions.h:349
mysqlpp::ConnectionFailed::ConnectionFailed
ConnectionFailed(const char *w="", int e=0)
Create exception object.
Definition: exceptions.h:335
mysqlpp::DBSelectionFailed
Exception thrown when the program tries to select a new database and the database server refuses for ...
Definition: exceptions.h:360
mysqlpp::DBSelectionFailed::errnum
int errnum() const
Return the error number corresponding to the error message returned by what(), if any.
Definition: exceptions.h:380
mysqlpp::DBSelectionFailed::DBSelectionFailed
DBSelectionFailed(const char *w="", int e=0)
Create exception object.
Definition: exceptions.h:366
mysqlpp::Exception
Base class for all MySQL++ custom exceptions.
Definition: exceptions.h:46
mysqlpp::Exception::operator=
Exception & operator=(const Exception &rhs)
Assign another exception object's contents to this one.
Definition: exceptions.h:56
mysqlpp::Exception::~Exception
~Exception()
Destroy exception object.
Definition: exceptions.h:63
mysqlpp::Exception::what_
std::string what_
explanation of why exception was thrown
Definition: exceptions.h:85
mysqlpp::Exception::Exception
Exception(const std::string &w)
Create exception object.
Definition: exceptions.h:79
mysqlpp::Exception::Exception
Exception(const Exception &e) MAY_THROW()
Create exception object as copy of another.
Definition: exceptions.h:49
mysqlpp::Exception::Exception
Exception(const char *w="")
Create exception object.
Definition: exceptions.h:73
mysqlpp::Exception::what
virtual const char * what() const
Returns explanation of why exception was thrown.
Definition: exceptions.h:66
mysqlpp::MutexFailed
Exception thrown when a BeecryptMutex object fails.
Definition: exceptions.h:390
mysqlpp::MutexFailed::MutexFailed
MutexFailed(const char *w="lock failed")
Create exception object.
Definition: exceptions.h:393
mysqlpp::ObjectNotInitialized
Exception thrown when you try to use an object that isn't completely initialized.
Definition: exceptions.h:404
mysqlpp::ObjectNotInitialized::ObjectNotInitialized
ObjectNotInitialized(const char *w="")
Create exception object.
Definition: exceptions.h:407
mysqlpp::SelfTestFailed
Used within MySQL++'s test harness only.
Definition: exceptions.h:417
mysqlpp::SelfTestFailed::SelfTestFailed
SelfTestFailed(const std::string &w)
Create exception object.
Definition: exceptions.h:420
mysqlpp::TypeLookupFailed
Thrown from the C++ to SQL data type conversion routine when it can't figure out how to map the type.
Definition: exceptions.h:439
mysqlpp::TypeLookupFailed::TypeLookupFailed
TypeLookupFailed(const std::string &w)
Create exception object.
Definition: exceptions.h:442
mysqlpp::UseQueryError
Exception thrown when something goes wrong in processing a "use" query.
Definition: exceptions.h:255
mysqlpp::UseQueryError::UseQueryError
UseQueryError(const char *w="")
Create exception object.
Definition: exceptions.h:258
options.h
Declares the Option class hierarchy, used to implement connection options in Connection and DBDriver ...