Exceptions
rapsqlite defines the following exception classes, matching the aiosqlite API:
- exception rapsqlite.OperationalError
Bases:
DatabaseError
- exception rapsqlite.ProgrammingError
Bases:
DatabaseError
- exception rapsqlite.IntegrityError
Bases:
DatabaseError
Exception Hierarchy
All exceptions inherit from Error, which inherits from Python’s Exception:
Exception
└── Error
├── Warning
├── DatabaseError
│ ├── OperationalError
│ └── ProgrammingError
└── IntegrityError
Usage
from rapsqlite import connect, IntegrityError, OperationalError
async with connect("example.db") as conn:
try:
await conn.execute("INSERT INTO users (email) VALUES (?)", ["duplicate@example.com"])
except IntegrityError:
print("Duplicate email")
except OperationalError as e:
print(f"Database error: {e}")