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.62.4" />
9    <link rel="home" 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="previous" 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></div>
36      </div>
37      <p>
38        Before continuing, it is useful to spend a few moments on exception
39        handling in DB with the 
40        <span>java</span>.
41    </p>
42      <p>
43        
44        <span>Most</span>
45        DB methods throw 
46            
47            <tt class="classname">DatabaseException</tt>
48        in the event of a serious error. 
49        
50        
51        <span>
52            So your DB code must either catch this exception or declare it
53            to be throwable. Be aware that <tt class="classname">DatabaseException</tt> extends 
54            <tt class="classname">java.lang.Exception</tt>. For example:
55        </span>
56    </p>
57      <a id="java_intro1"></a>
58      <pre class="programlisting">import com.sleepycat.db.DatabaseException;
59
60    ...
61try 
62{
63    // DB and other code goes here
64}
65catch(DatabaseException e)
66{
67  // DB error handling goes here
68} </pre>
69      <p>
70        You can obtain the DB error number for a
71         
72        <tt class="classname">DatabaseException</tt> 
73        by using
74        
75        <span>
76            <tt class="methodname">DatabaseException.getErrno()</tt>. 
77            You can also obtain any error message associated with that error
78            using <tt class="methodname">DatabaseException.getMessage()</tt>.
79        </span>
80    </p>
81    </div>
82    <div class="navfooter">
83      <hr />
84      <table width="100%" summary="Navigation footer">
85        <tr>
86          <td width="40%" align="left"><a accesskey="p" href="databaseLimits.html">Prev</a> </td>
87          <td width="20%" align="center">
88            <a accesskey="u" href="introduction.html">Up</a>
89          </td>
90          <td width="40%" align="right"> <a accesskey="n" href="returns.html">Next</a></td>
91        </tr>
92        <tr>
93          <td width="40%" align="left" valign="top">Database Limits and Portability </td>
94          <td width="20%" align="center">
95            <a accesskey="h" href="index.html">Home</a>
96          </td>
97          <td width="40%" align="right" valign="top"> Error Returns</td>
98        </tr>
99      </table>
100    </div>
101  </body>
102</html>
103