1<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3<html xmlns="http://www.w3.org/1999/xhtml">
4  <head>
5    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6    <title>Exception Handling</title>
7    <link rel="stylesheet" href="gettingStarted.css" type="text/css" />
8    <meta name="generator" content="DocBook XSL Stylesheets V1.73.2" />
9    <link rel="start" href="index.html" title="Getting Started with Berkeley DB" />
10    <link rel="up" href="introduction.html" title="Chapter��1.��Introduction to Berkeley DB" />
11    <link rel="prev" href="databaseLimits.html" title="Database Limits and Portability" />
12    <link rel="next" href="returns.html" title="Error Returns" />
13  </head>
14  <body>
15    <div class="navheader">
16      <table width="100%" summary="Navigation header">
17        <tr>
18          <th colspan="3" align="center">Exception Handling</th>
19        </tr>
20        <tr>
21          <td width="20%" align="left"><a accesskey="p" href="databaseLimits.html">Prev</a>��</td>
22          <th width="60%" align="center">Chapter��1.��Introduction to Berkeley DB </th>
23          <td width="20%" align="right">��<a accesskey="n" href="returns.html">Next</a></td>
24        </tr>
25      </table>
26      <hr />
27    </div>
28    <div class="sect1" lang="en" xml:lang="en">
29      <div class="titlepage">
30        <div>
31          <div>
32            <h2 class="title" style="clear: both"><a id="coreExceptions"></a>Exception Handling</h2>
33          </div>
34        </div>
35      </div>
36      <p>
37        Before continuing, it is useful to spend a few moments on exception
38        handling in DB with the 
39        <span>java</span>.
40    </p>
41      <p>
42        
43        <span>Most</span>
44        DB methods throw 
45            
46            <code class="classname">DatabaseException</code>
47        in the event of a serious error. 
48        
49        
50        <span>
51            So your DB code must either catch this exception or declare it
52            to be throwable. Be aware that <code class="classname">DatabaseException</code> extends 
53            <code class="classname">java.lang.Exception</code>. For example:
54        </span>
55    </p>
56      <a id="java_intro1"></a>
57      <pre class="programlisting">import com.sleepycat.db.DatabaseException;
58
59    ...
60try 
61{
62    // DB and other code goes here
63}
64catch(DatabaseException e)
65{
66  // DB error handling goes here
67} </pre>
68      <p>
69        You can obtain the DB error number for a
70         
71        <code class="classname">DatabaseException</code> 
72        by using
73        
74        <span>
75            <code class="methodname">DatabaseException.getErrno()</code>. 
76            You can also obtain any error message associated with that error
77            using <code class="methodname">DatabaseException.getMessage()</code>.
78        </span>
79    </p>
80    </div>
81    <div class="navfooter">
82      <hr />
83      <table width="100%" summary="Navigation footer">
84        <tr>
85          <td width="40%" align="left"><a accesskey="p" href="databaseLimits.html">Prev</a>��</td>
86          <td width="20%" align="center">
87            <a accesskey="u" href="introduction.html">Up</a>
88          </td>
89          <td width="40%" align="right">��<a accesskey="n" href="returns.html">Next</a></td>
90        </tr>
91        <tr>
92          <td width="40%" align="left" valign="top">Database Limits and Portability��</td>
93          <td width="20%" align="center">
94            <a accesskey="h" href="index.html">Home</a>
95          </td>
96          <td width="40%" align="right" valign="top">��Error Returns</td>
97        </tr>
98      </table>
99    </div>
100  </body>
101</html>
102