• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt-6.x.4708/router/db-4.8.30/java/src/com/sleepycat/db/
1/*-
2 * See the file LICENSE for redistribution information.
3 *
4 * Copyright (c) 1997-2009 Oracle.  All rights reserved.
5 *
6 * $Id$
7 */
8package com.sleepycat.db;
9
10import com.sleepycat.db.internal.DbEnv;
11
12/**
13The root of all database exceptions.
14<p>
15Note that in some cases, certain methods return status values without issuing
16an exception. This occurs in situations that are not normally considered an
17error, but when some informational status is returned.  For example,
18{@link com.sleepycat.db.Database#get Database.get} returns {@link com.sleepycat.db.OperationStatus#NOTFOUND OperationStatus.NOTFOUND} when a
19requested key does not appear in the database.
20**/
21public class DatabaseException extends Exception {
22    private Environment dbenv;
23    private int errno;
24
25    /** Construct an exception with the specified cause exception. **/
26    public DatabaseException(Throwable t) {
27        super(t);
28        errno = 0;
29        dbenv = null;
30    }
31
32    /** Construct an exception with the specified message. **/
33    public DatabaseException(final String s) {
34        this(s, 0, (Environment)null);
35    }
36
37    /** Construct an exception with the specified message and error number. **/
38    public DatabaseException(final String s, final int errno) {
39        this(s, errno, (Environment)null);
40    }
41
42    /**
43    Construct an exception with the specified message and error number
44    associated with a database environment handle.
45    **/
46    public DatabaseException(final String s,
47                             final int errno,
48                             final Environment dbenv) {
49        super(s);
50        this.errno = errno;
51        this.dbenv = dbenv;
52    }
53
54    /* package */ DatabaseException(final String s,
55                                final int errno,
56                                final DbEnv dbenv) {
57        this(s, errno, (dbenv == null) ? null : dbenv.wrapper);
58    }
59
60    /**
61Return the environment in which the exception occurred.
62<p>
63This method may be called at any time during the life of the application.
64<p>
65@return
66The environment in which the exception occurred.
67    **/
68    public Environment getEnvironment() {
69        return dbenv;
70    }
71
72    /**
73    Get the error number associated with this exception.
74    <p>
75    Note that error numbers can be returned from system calls
76    and are system-specific.
77    **/
78    public int getErrno() {
79        return errno;
80    }
81
82    /** {@inheritDoc} */
83    public String toString() {
84        String s = super.toString();
85        if (errno != 0)
86            s += ": " + DbEnv.strerror(errno);
87        return s;
88    }
89}
90