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