Debian Codegraph @

docs/programmer_reference/am_misc_error.html

raw symbols SCIP
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 support</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="Berkeley DB Programmer's Reference Guide" />
10 <link rel="up" href="am_misc.html" title="Chapter 4.  Access Method Wrapup" />
11 <link rel="prev" href="am_misc_perm.html" title="Retrieved key/data permanence for C/C++" />
12 <link rel="next" href="am_misc_stability.html" title="Cursor stability" />
13 </head>
14 <body>
15 <div xmlns="" class="navheader">
16 <div class="libver">
17 <p>Library Version 11.2.5.3</p>
18 </div>
19 <table width="100%" summary="Navigation header">
20 <tr>
21 <th colspan="3" align="center">Error support</th>
22 </tr>
23 <tr>
24 <td width="20%" align="left"><a accesskey="p" href="am_misc_perm.html">Prev</a> </td>
25 <th width="60%" align="center">Chapter 4. 
26 Access Method Wrapup
27 </th>
28 <td width="20%" align="right"> <a accesskey="n" href="am_misc_stability.html">Next</a></td>
29 </tr>
30 </table>
31 <hr />
32 </div>
33 <div class="sect1" lang="en" xml:lang="en">
34 <div class="titlepage">
35 <div>
36 <div>
37 <h2 class="title" style="clear: both"><a id="am_misc_error"></a>Error support</h2>
38 </div>
39 </div>
40 </div>
41 <p>Berkeley DB offers programmatic support for displaying error return values.</p>
42 <p>The <a href="../api_reference/C/envstrerror.html" class="olink">db_strerror()</a> function returns a pointer to the error
43 message corresponding to any Berkeley DB error return, similar to the ANSI C
44 strerror function, but is able to handle both system error returns and
45 Berkeley DB specific return values.</p>
46 <p>For example:</p>
47 <a id="prog_am25"></a>
48 <pre class="programlisting">int ret;
49 ...
50 if ((ret = dbp-&gt;put(dbp, NULL, &amp;key, &amp;data, 0)) != 0) {
51 fprintf(stderr, "put failed: %s\n", db_strerror(ret));
52 return (1);
53 }</pre>
54 <p>There are also two additional error methods, <a href="../api_reference/C/dberr.html" class="olink">DB-&gt;err()</a> and
55 <code class="methodname">DB-&gt;errx()</code>. These methods work like the ANSI C X3.159-1989 (ANSI C) printf
56 function, taking a printf-style format string and argument list, and
57 writing a message constructed from the format string and arguments.</p>
58 <p>The <a href="../api_reference/C/dberr.html" class="olink">DB-&gt;err()</a> method appends the standard error string to the
59 constructed message; the <code class="methodname">DB-&gt;errx()</code> method does not. These methods
60 provide simpler ways of displaying Berkeley DB error messages. For example,
61 if your application tracks session IDs in a variable called session_id,
62 it can include that information in its error messages:</p>
63 <p>Error messages can additionally be configured to always include a prefix
64 (for example, the program name) using the <a href="../api_reference/C/dbset_errpfx.html" class="olink">DB-&gt;set_errpfx()</a> method.</p>
65 <a id="prog_am26"></a>
66 <pre class="programlisting">#define DATABASE "access.db"
67
68 int ret;
69
70 (void)dbp-&gt;set_errpfx(dbp, program_name);
71
72 if ((ret = dbp-&gt;open(dbp,
73 NULL, DATABASE, NULL, DB_BTREE, DB_CREATE, 0664)) != 0) {
74 dbp-&gt;err(dbp, ret, "%s", DATABASE);
75 dbp-&gt;errx(dbp,
76 "contact your system administrator: session ID was %d",
77 session_id);
78 return (1);
79 }</pre>
80 <p>For example, if the program were called my_app and the open call returned
81 an EACCESS system error, the error messages shown would appear as follows:</p>
82 <pre class="programlisting">my_app: access.db: Permission denied.
83 my_app: contact your system administrator: session ID was 14</pre>
84 </div>
85 <div class="navfooter">
86 <hr />
87 <table width="100%" summary="Navigation footer">
88 <tr>
89 <td width="40%" align="left"><a accesskey="p" href="am_misc_perm.html">Prev</a> </td>
90 <td width="20%" align="center">
91 <a accesskey="u" href="am_misc.html">Up</a>
92 </td>
93 <td width="40%" align="right"> <a accesskey="n" href="am_misc_stability.html">Next</a></td>
94 </tr>
95 <tr>
96 <td width="40%" align="left" valign="top">Retrieved key/data permanence for C/C++ </td>
97 <td width="20%" align="center">
98 <a accesskey="h" href="index.html">Home</a>
99 </td>
100 <td width="40%" align="right" valign="top"> Cursor stability</td>
101 </tr>
102 </table>
103 </div>
104 </body>
105 </html>