Sophie

Sophie

distrib > Mandriva > 2007.0 > x86_64 > media > main-release > by-pkgid > a4c98df40e78f6c892308fd6841f950a > files > 918

lib64db4.2-devel-4.2.52-11mdv2007.0.x86_64.rpm

<!--$Id: error.so,v 10.20 2003/10/18 19:16:00 bostic Exp $-->
<!--Copyright 1997-2003 by Sleepycat Software, Inc.-->
<!--All rights reserved.-->
<!--See the file LICENSE for redistribution information.-->
<html>
<head>
<title>Berkeley DB Reference Guide: Error support</title>
<meta name="description" content="Berkeley DB: An embedded database programmatic toolkit.">
<meta name="keywords" content="embedded,database,programmatic,toolkit,b+tree,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,Java,C,C++">
</head>
<body bgcolor=white>
<table width="100%"><tr valign=top>
<td><h3><dl><dt>Berkeley DB Reference Guide:<dd>Environment</dl></h3></td>
<td align=right><a href="../env/open.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../toc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../env/db_config.html"><img src="../../images/next.gif" alt="Next"></a>
</td></tr></table>
<p>
<h3 align=center>Error support</h3>
<p>Berkeley DB offers programmatic support for displaying error return values.
The <a href="../../api_c/env_strerror.html">db_strerror</a> function returns a pointer to the error
message corresponding to any Berkeley DB error return.  This is similar to the
ANSI C strerror interface, but can handle both system error returns and
Berkeley DB-specific return values.</p>
<p>For example:</p>
<blockquote><pre>int ret;
if ((ret = dbenv-&gt;set_cachesize(dbenv, 0, 32 * 1024, 1)) != 0) {
	fprintf(stderr, "set_cachesize failed: %s\n", db_strerror(ret));
	return (1);
}</pre></blockquote>
<p>There are also two additional error methods: <a href="../../api_c/env_err.html">DB_ENV-&gt;err</a> and
<a href="../../api_c/env_err.html">DB_ENV-&gt;errx</a>.  These methods work like the ANSI C printf function,
taking a printf-style format string and argument list, and writing a
message constructed from the format string and arguments.</p>
<p>The <a href="../../api_c/env_err.html">DB_ENV-&gt;err</a> function appends the standard error string to the
constructed message; the <a href="../../api_c/env_err.html">DB_ENV-&gt;errx</a> function does not.</p>
<p>Error messages can be configured always to include a prefix (for
example, the program name) using the <a href="../../api_c/env_set_errpfx.html">DB_ENV-&gt;set_errpfx</a> method.</p>
<p>These functions provide simpler ways of displaying Berkeley DB error messages:</p>
<blockquote><pre>int ret;
dbenv-&gt;set_errpfx(dbenv, program_name);
if ((ret = dbenv-&gt;open(dbenv, home,
    DB_CREATE | DB_INIT_LOG | DB_INIT_TXN | DB_USE_ENVIRON, 0))
    != 0) {
	dbenv-&gt;err(dbenv, ret, "open: %s", home);
	dbenv-&gt;errx(dbenv,
	    "contact your system administrator: session ID was %d",
	    session_id);
	return (1);
}</pre></blockquote>
<p>For example, if the program was called "my_app", and it tried to open
an environment home directory in "/tmp/home" and the open call returned
a permission error, the error messages shown would look like this:</p>
<blockquote><pre>my_app: open: /tmp/home: Permission denied.
my_app: contact your system administrator: session ID was 2</pre></blockquote>
<table width="100%"><tr><td><br></td><td align=right><a href="../env/open.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../toc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../env/db_config.html"><img src="../../images/next.gif" alt="Next"></a>
</td></tr></table>
<p><font size=1><a href="../../sleepycat/legal.html">Copyright (c) 1996-2003</a> <a href="http://www.sleepycat.com">Sleepycat Software, Inc.</a> - All rights reserved.</font>
</body>
</html>