1<!--$Id: cxx.so,v 1.3 2002/08/27 02:28:31 bostic Exp $--> 2<!--Copyright (c) 1997,2008 Oracle. All rights reserved.--> 3<!--See the file LICENSE for redistribution information.--> 4<html> 5<head> 6<title>Berkeley DB Reference Guide: Release 4.1: C++ exceptions</title> 7<meta name="description" content="Berkeley DB: An embedded database programmatic toolkit."> 8<meta name="keywords" content="embedded,database,programmatic,toolkit,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,Java,C,C++"> 9</head> 10<body bgcolor=white> 11<table width="100%"><tr valign=top> 12<td><b><dl><dt>Berkeley DB Reference Guide:<dd>Upgrading Berkeley DB Applications</dl></b></td> 13<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> 14</td></tr></table> 15<p align=center><b>Release 4.1: C++ exceptions</b></p> 16<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 17can throw exceptions from their constructors. For example, this can 18happen if invalid parameters are passed in or the underlying C 19structures could not be created. If the objects are created in an 20environment that is not configured for exceptions (that is, the 21<a href="../../api_c/env_class.html#DB_CXX_NO_EXCEPTIONS">DB_CXX_NO_EXCEPTIONS</a> flag is specified), errors from the 22constructor will be returned when the handle's open method is called.</p> 23<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> 24destructors has changed to simplify exception handling in applications. 25The destructors will now close the handle if the handle's close method 26was not called prior to the object being destroyed. The return value 27of the call is discarded, and no exceptions will be thrown. 28Applications should call the close method in normal situations so any 29errors while closing can be handled by the application.</p> 30<p>This change allows applications to be structured as follows:</p> 31<blockquote><pre>try { 32 DbEnv env(0); 33 env.open(/* ... */); 34 Db db(&env, 0); 35 db.open(/* ... */); 36 /* ... */ 37 db.close(0); 38 env.close(0); 39} catch (DbException &dbe) { 40 // Handle the exception, the handles have already been closed. 41}</pre></blockquote> 42<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> 43</td></tr></table> 44<p><font size=1>Copyright (c) 1996,2008 Oracle. All rights reserved.</font> 45</body> 46</html> 47