dtl
![]() |
![]() |
Category: exceptions | Component type: type |
DBException is thrown when one of the database specific classes such as DBView or DBStmt encounters an error. An exception of this type stores strings representing which method the exception was thrown in and a message describing what error occurred. DBException also captures a vector of SQL errors (if any) that occurred to trigger this exception. The call to the constructor initializes these constructs (see below). The user can extract a stringified message with all of this information from the exception using the standard what() method.
Defined in the DBException.h header file.
void IWillThrow()
{
DBStmt("THIS SQL QUERY WON'T EXECUTE").Execute();
// this *definitely* will throw DBException
//
will print out ODBC msg. specifying this blatant syntax error!
}
int main()
{
try
{
DBConnection::GetDefaultConnection.Connect("UID=example;PWD=example;DSN=example");
// call our method which
throws
IWillThrow();
}
catch (RootException &ex)
{
// can also say: cout
<< ex << endl;
// operator<<() for
RootExceptions just streams out what()
cout << ex.what()
<< endl;
}
return 0; // won't reach here ... exception
thrown above
}
Standard C++ library exception.
RootException
Member | Where defined | Description |
---|---|---|
DBException(const string &meth, const string &msg, DBConnection *conn, DBStmt *stmt) | DBException | Constructor which takes a specific
method indicating where exception is being thrown, an
error message describing the problem encountered, and
pointers to the DBConnection
and DBStmt objects
being used in the operation that threw or NULL using the following
convention:
The constructor calls a private method ShowSQLErrors() to generate the vector of any SQL errors that triggered this exception if either pointer is non-NULL. |
virtual const char* what() const throw() | DBException | Overrides behavior in RootException. Returns a C string describing the exception, including the method it was thrown in, the error message describing why it was thrown, any SQL errors that led to the exception being thrown, and what type of exception was thrown. Subclasses do and may override what() based on their needs. See Note [1] in RootException. |
friend ostream &operator<<(ostream &o, const RootException &ex) | RootException | Note that this is a friend function, and not a member. Streams out ex.what() to o. As what() is virtual, the appropriate version of that method will be called for ex. |
pair<string, string> GetODBCError() | DBException | Prints out a pair containing strings indicating the SQL state and description of the ODBC error that caused this exception to be thrown. |
None.
Copyright © 2001, Michael Gradman and Corwin Joy.
Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appears in all copies and that both that copyright notice and this permission notice appear in supporting documentation. Corwin Joy and Michael Gradman make no representations about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty.