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>Error Reporting Functions</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="DB.html" title="Chapter��7.��Databases" /> 11 <link rel="prev" href="DBAdmin.html" title="Administrative Methods" /> 12 <link rel="next" href="CoreEnvUsage.html" title="Managing Databases in Environments" /> 13 </head> 14 <body> 15 <div class="navheader"> 16 <table width="100%" summary="Navigation header"> 17 <tr> 18 <th colspan="3" align="center">Error Reporting Functions</th> 19 </tr> 20 <tr> 21 <td width="20%" align="left"><a accesskey="p" href="DBAdmin.html">Prev</a>��</td> 22 <th width="60%" align="center">Chapter��7.��Databases</th> 23 <td width="20%" align="right">��<a accesskey="n" href="CoreEnvUsage.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="dbErrorReporting"></a>Error Reporting Functions</h2> 33 </div> 34 </div> 35 </div> 36 <p> 37 To simplify error reporting and handling, the 38 39 40 <span><code class="classname">DatabaseConfig</code> class</span> 41 offers several useful methods. 42 43 44 45 46 </p> 47 <div class="itemizedlist"> 48 <ul type="disc"> 49 <li> 50 <p> 51 52 <code class="methodname">DatabaseConfig.setErrorStream()</code> 53 </p> 54 <p> 55 Sets the 56 57 <span>Java <code class="classname">OutputStream</code></span> 58 to be used for displaying error messages issued by the DB library. 59 </p> 60 </li> 61 <li> 62 <p> 63 64 <code class="methodname">DatabaseConfig.setMessageHandler()</code> 65 </p> 66 <p> 67 Defines the message handler that is called when an error message is 68 issued by DB. The error prefix and message are passed to 69 this callback. It is up to the application to display this 70 information correctly. 71 </p> 72 <p> 73 Note that the message handler must be an implementation of the 74 <code class="classname">com.sleepycat.db.MessageHandler</code> 75 interface. 76 </p> 77 </li> 78 <li> 79 <p> 80 81 <code class="methodname">DatabaseConfig.setErrorPrefix()</code> 82 </p> 83 <p> 84 Sets the prefix used for any error messages issued by the 85 DB library. 86 </p> 87 </li> 88 </ul> 89 </div> 90 <p> 91 For example, to send all your error messages to a particular message 92 handler, first implement the handler: 93 </p> 94 <a id="java_db10"></a> 95 <pre class="programlisting">package db.GettingStarted; 96 97import com.sleepycat.db.Environment; 98import com.sleepycat.db.MessageHandler; 99 100public class MyMessageHandler implements MessageHandler { 101 102 // Our constructor does nothing 103 public MyMessageHandler() {} 104 105 public void message(Environment dbenv, String message) 106 { 107 // Put your special message handling code here 108 } 109 110}</pre> 111 <p> 112 And then set up your database to use the message handler by identifying 113 it on the database's <code class="classname">DatabaseConfig</code> object: 114 </p> 115 <a id="java_db11"></a> 116 <pre class="programlisting">package db.GettingStarted; 117 118import com.sleepycat.db.DatabaseConfig; 119 120... 121 122DatabaseConfig myDbConfig = new DatabaseConfig(); 123MyMessageHandler mmh = new MyMessageHandler(); 124myDbConfig.setMessageHandler(mmh); </pre> 125 </div> 126 <div class="navfooter"> 127 <hr /> 128 <table width="100%" summary="Navigation footer"> 129 <tr> 130 <td width="40%" align="left"><a accesskey="p" href="DBAdmin.html">Prev</a>��</td> 131 <td width="20%" align="center"> 132 <a accesskey="u" href="DB.html">Up</a> 133 </td> 134 <td width="40%" align="right">��<a accesskey="n" href="CoreEnvUsage.html">Next</a></td> 135 </tr> 136 <tr> 137 <td width="40%" align="left" valign="top">Administrative Methods��</td> 138 <td width="20%" align="center"> 139 <a accesskey="h" href="index.html">Home</a> 140 </td> 141 <td width="40%" align="right" valign="top">��Managing Databases in Environments</td> 142 </tr> 143 </table> 144 </div> 145 </body> 146</html> 147