<!--$Id: cxx.so,v 1.3 2002/08/27 02:28:31 bostic Exp $-->
<!--Copyright (c) 1997,2008 Oracle. All rights reserved.-->
<!--See the file LICENSE for redistribution information.-->
<html>
<head>
<title>Berkeley DB Reference Guide: Release 4.1: C++ exceptions</title>
<meta name="description" content="Berkeley DB: An embedded database programmatic toolkit.">
<meta name="keywords" content="embedded,database,programmatic,toolkit,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,Java,C,C++">
</head>
<body bgcolor=white>
<table width="100%"><tr valign=top>
<td><b><dl><dt>Berkeley DB Reference Guide:<dd>Upgrading Berkeley DB Applications</dl></b></td>
<td align=right><a href="../upgrade.4.1/java.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../toc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../upgrade.4.1/app_dispatch.html"><img src="../../images/next.gif" alt="Next"></a>
</td></tr></table>
<p align=center><b>Release 4.1: C++ exceptions</b></p>
<p>With default flags, the C++ <a href="../../api_cxx/env_class.html">DbEnv</a> and <a href="../../api_cxx/db_class.html">Db</a> classes
can throw exceptions from their constructors. For example, this can
happen if invalid parameters are passed in or the underlying C
structures could not be created. If the objects are created in an
environment that is not configured for exceptions (that is, the
<a href="../../api_c/env_class.html#DB_CXX_NO_EXCEPTIONS">DB_CXX_NO_EXCEPTIONS</a> flag is specified), errors from the
constructor will be returned when the handle's open method is called.</p>
<p>In addition, the behavior of the <a href="../../api_cxx/env_class.html">DbEnv</a> and <a href="../../api_cxx/db_class.html">Db</a>
destructors has changed to simplify exception handling in applications.
The destructors will now close the handle if the handle's close method
was not called prior to the object being destroyed. The return value
of the call is discarded, and no exceptions will be thrown.
Applications should call the close method in normal situations so any
errors while closing can be handled by the application.</p>
<p>This change allows applications to be structured as follows:</p>
<blockquote><pre>try {
DbEnv env(0);
env.open(/* ... */);
Db db(&env, 0);
db.open(/* ... */);
/* ... */
db.close(0);
env.close(0);
} catch (DbException &dbe) {
// Handle the exception, the handles have already been closed.
}</pre></blockquote>
<table width="100%"><tr><td><br></td><td align=right><a href="../upgrade.4.1/java.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../toc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../upgrade.4.1/app_dispatch.html"><img src="../../images/next.gif" alt="Next"></a>
</td></tr></table>
<p><font size=1>Copyright (c) 1996,2008 Oracle. All rights reserved.</font>
</body>
</html>
Copyright 2K16 - 2K18 Indonesian Hacker Rulez