|Official GNU Software|
14 Error handling.
The global variable
gdbm_errno (see gdbm_errno)
keeps the error code of the most recent error encountered by GDBM
To convert this code to human-readable string, use the following function:
- gdbm interface: const char * gdbm_strerror (gdbm_error errno)
Converts errno (which is an integer value) into a human-readable descriptive text. Returns a pointer to a static string. The caller must not alter or free the returned pointer.
Detailed information about the most recent error that occurred while
operating on a GDBM file is stored in the
itself. To retrieve it, the following functions are provided:
- gdbm interface: gdbm_error gdbm_last_errno (GDBM_FILE dbf)
Returns the code of the most recent error encountered when operating on dbf.
- gdbm interface: int gdbm_last_syserr (GDBM_FILE dbf)
Returns the value of the system
errnovariable associated with the most recent error.
Notice, that not all GDBM errors have an associated system error code. The following are the ones that have:
For other errors,
gdbm_last_syserrwill return 0.
- gdbm interface: int gdbm_check_syserr (gdbm_errno err)
1, if system errno value should be checked to get more info on the error described by GDBM code err.
To get a human-readable description of the recent error for a
particular database file, use the
- gdbm interface: const char * gdbm_db_strerror (GDBM_FILE dbf)
Returns textual description of the most recent error encountered when operating on the database dbf. The resulting string is often more informative than what would be returned by ‘gdbm_strerror(gdbm_last_errno(dbf))’. In particular, if there is a system error associated with the recent failure, it will be described as well.
- gdbm interface: void gdbm_clear_error (GDBM_FILE dbf)
Clears the error state for the database dbf. Normally, this function is called upon the entry to any GDBM function.
Certain errors (such as write error when saving stored key) can leave
database file in inconistent state. When such a critical error
occurs, the database file is marked as needing recovery. Subsequent
calls to any GDBM functions for that database file (except
gdbm_recover), will return immediately with GDBM error value
GDBM_NEED_RECOVERY. Additionally, the following
function can be used to check the state of the database file:
- gdbm interface: int gdbm_needs_recovery (GDBM_FILE dbf)
1if the database file dbf is in inconsistent state and needs recovery.
The only way to bring the database back to operational state is to
gdbm_recover function (see Recovery).