all Python 3sqlite3exception
sqlite3.DatabaseError
exceptions
Raised for errors related to the database; base class for the specialised sqlite3 errors (OperationalError, IntegrityError, ...), subclass of sqlite3.Error.
Syntax
raise sqlite3.DatabaseError
In practice you catch either sqlite3.Error, which also covers InterfaceError (misuse of the module rather than a database problem), or DatabaseError when only database-side failures matter. To tell the exact cause apart, lean on the sqlite_errorcode and sqlite_errorname attributes instead of the class hierarchy — since Python 3.11 exceptions that come from the SQLite library itself carry them (module-level errors such as ProgrammingError do not).
Examples
import sqlite3
print(issubclass(sqlite3.IntegrityError, sqlite3.DatabaseError)) # → True
try:
sqlite3.connect(':memory:').execute('SELECT bad syntax here')
except sqlite3.DatabaseError as e:
print(type(e).__name__) # → OperationalError
See also
Open in the full glossarydocs.python.orgReport an inaccuracy