⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dbexception.htm

📁 The goal of this library is to make ODBC recordsets look just like an STL container. As a user, you
💻 HTM
字号:
<html>

<head>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<meta name="GENERATOR" content="Microsoft FrontPage Express 2.0">
<title></title>
</head>

<body>


<head>
<style>
CODE {COLOR: #990000;}
.code{COLOR: #990000}
.codeComment{COLOR: #008000}
.codeHighlight{BACKGROUND-COLOR: #FFFF00}
.codeFileName{FONT-WEIGHT: bold;}
</style>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<meta name="Author" content="Mike Gradman">
<meta name="KeyWords"
content="DTL, Oracle, ODBC, database API, C++, Template Library">
<meta name="GENERATOR" content="Microsoft FrontPage Express 2.0">
<!--
  -- Copyright 2000
  -- Michael Gradman & 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 & Michael Gradman make no
  -- representations about the suitability of this software for any
  -- purpose.  It is provided "as is" without express or implied warranty.
  --
  --
  -- Copyright (c) 1996-1999
  -- Silicon Graphics Computer Systems, Inc.
  --
  -- 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.  Silicon Graphics makes no
  -- representations about the suitability of this software for any
  -- purpose.  It is provided "as is" without express or implied warranty.
  --
  -- Copyright (c) 1994
  -- Hewlett-Packard Company
  --
  -- 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.  Hewlett-Packard Company makes no
  -- representations about the suitability of this software for any
  -- purpose.  It is provided "as is" without express or implied warranty.
  --
  -->
<!-- Generated by htmldoc -->
<title>DBException</title>
</head>

<body bgcolor="#FFFFFF" text="#000000" link="#0000EE"
vlink="#551A8B" alink="#FF0000">

<p><font size="6" face="Bookman Old Style"><em><strong><u>dtl</u></strong></em></font></p>

<p><img src="stat.gif" width="6" height="6"> <!--end header--> <br>
</p>
<h1>DBException</h1>

 


















<table border="0" cellpadding="0" cellspacing="0" width="100%">
    <tr>
        <td><img src="exceptions.gif" width="194" height="38"></td>
        <td align="right"><img src="type.gif" width="194"
        height="39"></td>
    </tr>
    <tr>
        <td valign="top"><b>Category</b>: exceptions</td>
        <td align="right" valign="top"><b>Component type</b>:
        type</td>
    </tr>
</table>
<h3>Description</h3>

<p><tt>DBException </tt>is thrown when one of the database
specific classes such as <font size="2" face="Courier New">DBView</font>
or <font size="2" face="Courier New">DBStmt</font> 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. <tt>DBException </tt>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 <font
size="2" face="Courier New">what() </font><font size="3">method.</font></p>

<h3>Definition</h3>

<p>Defined in the <font size="2" face="Courier New">DBException.h</font><font
size="1" face="Courier New"> </font>header file. </p>

<h3>Example: Throwing and catching a DBException ... executing an
invalid query directly using a DBStmt object</h3>

<p><code>void IWillThrow()<br>
{<br>
&nbsp;&nbsp;&nbsp;DBStmt(&quot;THIS SQL QUERY WON'T EXECUTE&quot;).Execute();
<span class="codeComment">// this *definitely* will throw DBException<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//
will print out ODBC msg. specifying this blatant syntax error!</span><br>
}<br>
<br>
int main()<br>
{<br>
&nbsp;&nbsp;&nbsp;try<br>
&nbsp;&nbsp;&nbsp;{<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DBConnection::GetDefaultConnection.Connect(&quot;UID=example;PWD=example;DSN=example&quot;);<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="codeComment">// call our method which
throws</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; IWillThrow();<br>
&nbsp;&nbsp;&nbsp;}<br>
&nbsp;&nbsp;&nbsp;catch (RootException &amp;ex)<br>
&nbsp;&nbsp;&nbsp;{<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /<span class="codeComment">/ can also say: cout
&lt;&lt; ex &lt;&lt; endl;</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="codeComment">// operator&lt;&lt;() for
RootExceptions just streams out what()</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cout &lt;&lt; ex.what()
&lt;&lt; endl;<br>
&nbsp;&nbsp;&nbsp;}<br>
&nbsp;&nbsp;&nbsp;return 0; <span class="codeComment">// won't reach here ... exception
thrown above</span><br>
}</code></p>

<h3>Model of</h3>

<p>Standard C++ library exception.</p>

<h3>Public base classes</h3>

<p><font size="2" face="Courier New">RootException</font></p>

<h3>Members</h3>

<table border="2">
    <tr>
        <th>Member </th>
        <th>Where defined </th>
        <th>Description </th>
    </tr>
    <tr>
        <td valign="top"><font size="2" face="Courier New">DBException(const
        string &amp;meth, const string &amp;msg, DBConnection *conn,
        DBStmt *stmt)</font></td>
        <td valign="top"><tt>DBException</tt></td>
        <td valign="top">Constructor which takes a specific
        method indicating where exception is being thrown, an
        error message describing the problem encountered, and
        pointers to the <font size="2" face="Courier New">DBConnection
        </font>and <font size="2" face="Courier New">DBStmt </font>objects
        being used in the operation that threw or <font size="2"
        face="Courier New">NULL </font>using the following
        convention: <ul>
            <li>If the exception occurred due to a bad API call
                and involved no actual accesses to the database,
                pass <font size="2" face="Courier New">NULL </font>for
                both pointers.</li>
            <li>If the exception occurred due to a bad ODBC call
                (thus accesses to the database were bad) and
                involved a <font size="2" face="Courier New">DBConnection
                connxn, </font>but no associated <font size="2"
                face="Courier New">DBStmt, </font>pass in <font
                size="2" face="Courier New">&amp;connxn</font>
                for the <font size="2" face="Courier New">conn</font>
                parameter and <font size="2" face="Courier New">NULL</font>
                for <font size="2" face="Courier New">stmt</font>.</li>
            <li>If the exception occurred due to a bad ODBC call
                (thus accesses to the database were bad) and
                involved a <font size="2" face="Courier New">DBStmt
                statement, </font><font size="3">remember that
                there is an associated </font><font size="2"
                face="Courier New">DBConnection </font><font
                size="3">with that</font><font size="2"
                face="Courier New"> DBStmt, </font><font size="3">accessible
                by calling </font><font size="2"
                face="Courier New">statement.GetConnection(). </font><font
                size="3">So in this case, pass in </font><font
                size="2" face="Courier New">&amp;(statement.GetConnection())
                </font>for the <font size="2" face="Courier New">conn</font>
                parameter and <font size="2" face="Courier New">&amp;statement</font>
                for <font size="2" face="Courier New">stmt</font>.</li>
        </ul>
        <p>The constructor calls a private method <font size="2"
        face="Courier New">ShowSQLErrors() </font>to generate the
        vector of any SQL errors that triggered this exception if
        either pointer is non-<font size="2" face="Courier New">NULL.</font></p>
        </td>
    </tr>
    <tr>
        <td valign="top"><font size="2" face="Courier New">virtual
        const char* what() const throw()</font></td>
        <td valign="top"><tt>DBException</tt> </td>
        <td valign="top">Overrides behavior in <font size="2"
        face="Courier New">RootException. </font><font size="3">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 </font><font size="2"
        face="Courier New">what() </font>based on their needs. <font
        size="3">See Note </font><a href="RootException.htm#1"><font
        size="3">[1]</font></a><font size="3"> in </font><a
        href="RootException.htm"><tt>RootException</tt></a><font
        size="3">.</font></td>
    </tr>
    <tr>
        <td valign="top"><tt>friend ostream &amp;operator&lt;&lt;(ostream
        &amp;o, const RootException &amp;ex)</tt></td>
        <td valign="top"><tt>RootException</tt> </td>
        <td valign="top">Note that this is a friend function, and
        not a member. Streams out <font size="2"
        face="Courier New">ex.what()</font><font size="3"> to </font><font
        size="2" face="Courier New">o.</font><font size="3"> As </font><font
        size="2" face="Courier New">what() </font><font size="3">is
        virtual, the appropriate version of that method will be
        called for </font><font size="2" face="Courier New">ex.</font></td>
    </tr>
    <tr>
        <td valign="top"><tt>pair&lt;string, string&gt;
        GetODBCError()</tt></td>
        <td valign="top"><tt>DBException</tt> </td>
        <td valign="top">Prints out a pair containing strings indicating
        the SQL state and description
        of the ODBC error that caused this exception to be thrown.</td>
    </tr>
</table>

<h3>Notes</h3>

<p>None.</p>

<h3>See also</h3>

<p><a href="RootException.htm"><tt>RootException</tt></a>.<br>
<br>
</p>

<p>
<hr>

<p><a href="index.htm"><img src="dtl_home.gif" alt="[DTL Home]"
width="54" height="54"></a> <br>
</p>

<p>Copyright 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -