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

📄 rootexception.htm

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


<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>RootException</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>RootException</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>RootException</tt> is the base class of all exceptions in
the DTL. An exception of this type stores strings representing
which method the exception was thrown in, a message describing
what error occurred, and what actual exception type was thrown.
The call to the constructor initializes these strings. 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.
Subclasses may also pass in a stringified representation of their
type name as the third argument to the constructor (see below).</font></p>

<h3>Definition</h3>

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

<h3>Example: Trivial case of throwing and catching a
RootException</h3>

<p><code>void IWillThrow()<br>
{<br>
&nbsp;&nbsp; vector&lt;int&gt; v(5); <span class="codeComment">// create a vector of 5
elements</span><br>
&nbsp;&nbsp;&nbsp;try<br>
&nbsp;&nbsp;&nbsp;{<br>
&nbsp;&nbsp;&nbsp;for (int i = 0; i &lt;= 5; i++){<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;v.at(i) = i; <span class="codeComment">// v.at(5) will
throw std::invalid_argument exception</span><br>
&nbsp;&nbsp;&nbsp;}<br>
&nbsp;&nbsp;&nbsp;catch (invalid_argument &amp;ex)<br>
&nbsp;&nbsp;&nbsp;{<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="codeComment">// for a method SomeClass::foo(),
method string would be &quot;SomeClass:foo()&quot;</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="codeComment">// for a global function as
used here, just use its name</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;throw RootException(&quot;IWillThrow()&quot;,
ex.what());<br>
&nbsp;&nbsp;&nbsp;}<br>
};<br>
<br>
int main()<br>
{<br>
&nbsp;&nbsp;&nbsp;try<br>
&nbsp;&nbsp;&nbsp;{<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">std::exception</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">RootException()</font></td>
        <td valign="top"><tt>RootException</tt> </td>
        <td valign="top"><font size="3">Default constructor. Sets
        method and message fields to empty strings and exception
        type string to &quot;RootException&quot;.</font></td>
    </tr>
    <tr>
        <td valign="top"><font size="2" face="Courier New">RootException(const
        string &amp;meth, const string &amp;err, const string
        &amp;excType = &quot;RootException&quot;)</font></td>
        <td valign="top"><tt>RootException</tt> </td>
        <td valign="top">Constructor which takes a specific
        method, error string, and stringified exception type to
        initialize itself.</td>
    </tr>
    <tr>
        <td valign="top"><font size="2" face="Courier New">virtual
        const char* what() const throw()</font></td>
        <td valign="top"><tt>RootException</tt> </td>
        <td valign="top">Overrides behavior in <font size="2"
        face="Courier New">std::exception. </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, 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="#1"><font size="3">[1]</font></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>
</table>

<h3>Notes</h3>

<p><a name="1"></a>[1] A <tt>RootException</tt> contains a
protected <font size="2" face="Courier New">string </font><font
size="3">member named </font><font size="2" face="Courier New">whatbuf.
</font><font size="3">This seemingly extra member is needed as
the </font><font size="2" face="Courier New">std::exception </font><font
size="3">does not contain a <strong>portable</strong>, <strong>mutable
</strong>way to access its own member that is used to hold the
error message. This effects the implementation of the </font><font
size="2" face="Courier New">what() </font><font size="3">method
as the exception needs a way to build its own error string,
possibly partly based on what the superclass exception does in
its work. An example of how to implement </font><font size="2"
face="Courier New">what() </font><font size="3">for a subclass of
</font><tt>RootException </tt><font size="4"
face="Times New Roman"><tt>can be found in the </tt></font><font
size="3"><tt>DBException</tt></font><font size="4"
face="Times New Roman"><tt> class:</tt></font></p>

<p><font size="3"><tt>// DBException::what() ... DBException
derives from RootException<br>
virtual const char *what() const throw()<br>
{<br>
&nbsp;&nbsp;&nbsp;string rootWhat = RootException::what(); // let
RootException build up the common part of the error string<br>
&nbsp;&nbsp;&nbsp;ostringstream o;<br>
&nbsp;&nbsp;&nbsp;o &lt;&lt; rootWhat;<br>
<br>
&nbsp;&nbsp;&nbsp;// stream out ODBC errors to the what() string<br>
&nbsp;&nbsp;&nbsp;if (sqlErrors.size() &gt; 0)<br>
&nbsp;&nbsp;&nbsp;{<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; o &lt;&lt; &quot;SQL Errors:
&quot; &lt;&lt; endl;<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (size_t i = 0; i &lt;
sqlErrors.size(); i++)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;o &lt;&lt;
&quot;(&quot; &lt;&lt; i &lt;&lt; &quot;) &quot; &lt;&lt;
sqlErrors[i] &lt;&lt; endl;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>
<br>
&nbsp;&nbsp;&nbsp;}<br>
<br>
&nbsp;&nbsp;&nbsp;// this gymnastics is needed so result isn't
destroyed<br>
&nbsp;&nbsp;&nbsp;// paste these two lines into all what() code<br>
&nbsp;&nbsp;&nbsp;whatbuf = o.str();<br>
&nbsp;&nbsp;&nbsp;return whatbuf.c_str();<br>
}<br>
</tt></font></p>

<h3>See also</h3>

<p><a href="DBException.htm"><font size="2" face="Courier New">DBException</font></a>,
<a href="ETIException.htm"><font size="2" face="Courier New">ETIException,</font></a>
<a href="ValidityException.htm"><font size="2" face="Courier New">ValidityException</font></a>,
<a href="VariantException.htm"><font size="2" face="Courier New">VariantException</font></a>.<br>
<br>
</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 + -