Overview
BinaryDB defines a hierarchy of exception classes for different error conditions. All exceptions inherit fromDatabaseError, allowing you to catch all database-related errors with a single except clause.
Exception Hierarchy
DatabaseError
Base class:Exception
Base exception for all database-related errors. Use this to catch any error from BinaryDB operations.
When Raised
- When the database is closed and operations are attempted
- As a base class for all other database exceptions
Example
DatabaseIOError
Base class:DatabaseError
Raised when disk I/O operations fail during commit or load operations.
When Raised
- When
commit()fails to write to disk (permission denied, disk full, etc.) - When the temporary file cannot be created during atomic writes
- When file replacement fails
Example
DatabaseCorruptedError
Base class:DatabaseError
Raised when the database file format is invalid or corrupted.
When Raised
- When
load()fails to unpickle the database file - When the loaded data is not a dictionary
- When the file is corrupted or incompatible
Example
KeyValidationError
Base class:DatabaseError
Raised when a database key is invalid.
When Raised
- When a key is not a string
- When a key is an empty string
- Raised by:
set(),get(),delete(),update(),exists()
Example
RecordTypeError
Base class:DatabaseError
Raised when a stored record has an unexpected type.
When Raised
- When
update()is called on a non-dictionary record - Only applies to the
update()method, which requires dict records
Example
TransactionError
Base class:DatabaseError
Raised on invalid transaction operations.
When Raised
- When
begin()is called while a transaction is already active - When
end()is called without an active transaction - When
rollback()is called without an active transaction
Example
ConcurrencyError
Base class:DatabaseError
Raised when concurrent access rules are violated.
When Raised
Currently defined but not actively used in the implementation. Reserved for future concurrency control features such as:- File locking conflicts
- Multiple process access
- Optimistic locking failures
Example
Error Handling Best Practices
Catch Specific Exceptions
Catch specific exceptions when you need different handling for different errors:Catch All Database Errors
For general error handling, catchDatabaseError:
