Library Version 12.1.6.2

Chapter 6. The DbException Class
Prev |  | Next

## Chapter 6. The DbException Class

    #include <db_cxx.h>
    class DbException {
    public:
        int get_errno() const;
        virtual const char *what() const;
        DbEnv *get_env() const;
    };

This information describes the `DbException` class and how it is used by the various Berkeley DB classes.

Most methods in the Berkeley DB classes return an `int`, but also throw an exception. This allows for two different error behaviors. By default, the Berkeley DB C++ API is configured to throw an exception whenever a serious error occurs. This generally allows for cleaner logic for transaction processing because a try block can surround a single transaction. Alternatively, Berkeley DB can be configured to not throw exceptions, and instead have the individual function return an error code, by setting the DB_CXX_NO_EXCEPTIONS for the Db and DbEnv constructors.

A `DbException` object contains an informational string, an `errno`, and a reference to the environment from which the exception was thrown. The `errno` can be obtained by using the `DbException::get_errno()` method, and can be used, in standard cases, to determine the type of the exception. The informational string can be obtained by using the `DbException::what()`. And, the environment can be obtained using the `DbException::get_env()` method.

Where available, this class inherits from the standard class exception.

Some methods may return non-zero values without issuing an exception. This occurs in situations that are not normally considered an error, but when some informational status is returned. For example, the Db::get() method returns DB_NOTFOUND when a requested key does not appear in the database.

## DB C++ Exceptions

DB C++ Exceptions | Description
--- | ---
DbDeadlockException | Exception class for deadlocks
DbLockNotGrantedException | Exception class for lock request failures
DbMemoryException | Exception class for insufficient memory
DbRepHandleDeadException | Exception class for database and cursor handles that are invalidated in a replicated application.
DbRunRecoveryException | Exception class for failures requiring recovery

Prev |  | Next
DbEnv::version() | Home | DbDeadlockException