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

📄 validityexception.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>ValidityException</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>ValidityException</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>ValidityException</tt> is thrown by classes in the DTL
that derive from <font size="2" face="Courier New">ValidatedObject.
</font>Such classes maintain state information that allows them
to determine whether they are in a valid state or have been
corrupted. Once an operation is performed in one of these self-validating
classes that detects that the object is no longer in a valid
state, the operation will throw a <tt>ValidityException. </tt>An
exception of this type stores strings representing which method
the exception was thrown in and a message describing what error
occurred. 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.</font></p>

<h3>Definition</h3>

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

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

<p><code>class MoneyAccount : public
ValidatedObject<br>
{ <br>
private:<br>
&nbsp;&nbsp;&nbsp;<span class="codeComment">// if less than 0 money left, we're broke --&gt;
object corrupted!</span><br>
&nbsp;&nbsp;&nbsp;<span class="codeComment">// (must then see MoneyAccount manager to
revalidate() or go to jail:P)</span><br>
&nbsp;&nbsp;&nbsp;<span class="codeComment">// (in this example though, once you're in
debt, your account is frozen!)</span><br>
&nbsp;&nbsp;&nbsp;double balance;<br>
public:<br>
&nbsp;&nbsp;&nbsp;MoneyAccount(unsigned double initialDeposit) :
ValidatedObject(), balance(initialDeposit) { } <br>
<br>
&nbsp;&nbsp;&nbsp;<span class="codeComment">// should be able to see balance even if
account is frozen!</span><br>
&nbsp;&nbsp;&nbsp;double GetBalance() { return balance; }<br>
<br>
&nbsp;&nbsp;&nbsp;<span class="codeComment">// account only valid if not in debt!</span><br>
&nbsp;&nbsp;&nbsp;virtual bool valid()<br>
&nbsp;&nbsp;&nbsp;{<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="codeComment">// if we know the object is
invalid from a previous error,</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="codeComment">// object is still invalid (in
this case, account still frozen)</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (!ValidatedObject::valid())<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return
false;<br>
<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;<span class="codeComment">// freeze account by invalidating
object if in debt</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (balance &lt; 0)}<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;invalidate();<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return
false;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return
true;<br>
&nbsp;&nbsp;&nbsp;}<br>
<br>
&nbsp;&nbsp;&nbsp;<span class="codeComment">// these operations work only if the account is
not frozen</span><br>
&nbsp;&nbsp;&nbsp;void deposit(unsigned double amt)<br>
&nbsp;&nbsp;&nbsp;{<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;validate(); <span class="codeComment">// call to
validate will throw if object not valid</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;balance += amt;<br>
&nbsp;&nbsp;&nbsp;}<br>
<br>
&nbsp;&nbsp;&nbsp;double withdraw(unsigned double amt)<br>
&nbsp;&nbsp;&nbsp;{<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;validate(); <span class="codeComment">// call to
validate will throw if object not valid</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<span class="codeComment">// can withdraw up to how much we
have left in the account</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;double amtWithdrawn = (balance
- amt &gt;= 0 ? amt : balance);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;balance -= amtWithdrawn;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return amtWithdrawn; <span class="codeComment">//
return actual amount withdrawn</span><br>
&nbsp;&nbsp;&nbsp;}<br>
<br>
&nbsp;&nbsp;&nbsp;<span class="codeComment">// called by creditors to make bank pay!
Account could get frozen here!</span><br>
&nbsp;&nbsp;&nbsp;<span class="codeComment">// assume bank always pays creditors even if
account is frozen</span><br>
&nbsp;&nbsp;&nbsp;<span class="codeComment">// calls to any other MoneyAccount methods
should properly discover</span><br>
&nbsp;&nbsp;&nbsp;<span class="codeComment">// any new debt and thus freeze account</span><br>
&nbsp;&nbsp;&nbsp;void pay_creditors(unsigned double amt) {
balance -= amt; }<br>
};<br>
<br>
void IWillThrow()<br>
{ <br>
&nbsp;&nbsp;&nbsp;<span class="codeComment">// create account and then perform some
transactions</span><br>
&nbsp;&nbsp;&nbsp;MoneyAccount acct(200.00);<br>
&nbsp;&nbsp;&nbsp;acct.deposit(700.00);<br>
&nbsp;&nbsp;&nbsp;acct.withdraw(550.00);<br>
&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;<span class="codeComment">// uh oh ... now creditors take my money away,
my account is frozen</span><br>
&nbsp;&nbsp;&nbsp;acct.pay_creditors(1000);<br>
<br>
&nbsp;&nbsp;&nbsp;<span class="codeComment">// now trying to do something with my frozen
account will throw ValidityException</span><br>
&nbsp;&nbsp;&nbsp;acct.withdraw(50.00);<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">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">ValidityException(const
        string &amp;meth, const string &amp;obType, Revalidation
        reval = NONE_TRIED)</font></td>
        <td valign="top"><tt>ValidityException</tt> </td>
        <td valign="top">Constructor which takes a specific
        method where the exception is being thrown from and a
        stringified version of the type of the object where
        validation failed.</td>
    </tr>
    <tr>
        <td valign="top"><font size="2" face="Courier New">virtual
        const char* what() const throw()</font></td>
        <td valign="top"><tt>ValidityException</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 type of the object where validation
        failed, 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 class </font><a
        href="RootException.htm"><font size="2"
        face="Courier New">RootException</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>None.<font size="3"><tt><br>
</tt></font></p>

<h3>See also</h3>

<p><a href="RootException.htm"><font size="2" face="Courier New">RootException</font></a>,
<a href="ValidatedObject.htm"><font size="2"
face="Courier New">ValidatedObject</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 + -