2
<!--Copyright 1997-2002 by Sleepycat Software, Inc.-->
3
<!--All rights reserved.-->
4
<!--See the file LICENSE for redistribution information.-->
7
<title>Berkeley DB Reference Guide: Release 4.1: C++ exceptions</title>
8
<meta name="description" content="Berkeley DB: An embedded database programmatic toolkit.">
9
<meta name="keywords" content="embedded,database,programmatic,toolkit,b+tree,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,java,C,C++">
12
<table width="100%"><tr valign=top>
13
<td><h3><dl><dt>Berkeley DB Reference Guide:<dd>Upgrading Berkeley DB Applications</dl></h3></td>
14
<td align=right><a href="../../ref/upgrade.4.1/java.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../../reftoc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../../ref/upgrade.4.1/app_dispatch.html"><img src="../../images/next.gif" alt="Next"></a>
17
<h1 align=center>Release 4.1: C++ exceptions</h1>
18
<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
19
can throw exceptions from their constructors. For example, this can
20
happen if invalid parameters are passed in or the underlying C
21
structures could not be created. If the objects are created in an
22
environment that is not configured for exceptions (that is, the
23
<a href="../../api_c/env_class.html#DB_CXX_NO_EXCEPTIONS">DB_CXX_NO_EXCEPTIONS</a> flag is specified), errors from the
24
constructor will be returned when the handle's open method is called.
25
<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>
26
destructors has changed to simplify exception handling in applications.
27
The destructors will now close the handle if the handle's close method
28
was not called prior to the object being destroyed. The return value
29
of the call is discarded, and no exceptions will be thrown.
30
Applications should call the close method in normal situations so any
31
errors while closing can be handled by the application.
32
<p>This change allows applications to be structured as follows:
33
<p><blockquote><pre>try {
41
} catch (DbException &dbe) {
42
// Handle the exception, the handles have already been closed.
44
<table width="100%"><tr><td><br></td><td align=right><a href="../../ref/upgrade.4.1/java.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../../reftoc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../../ref/upgrade.4.1/app_dispatch.html"><img src="../../images/next.gif" alt="Next"></a>
46
<p><font size=1><a href="http://www.sleepycat.com">Copyright Sleepycat Software</a></font>