Catch the right thing, not the world
The sqlite3 module raises a small hierarchy of exceptions. Knowing them lets you handle expected failures (constraint violations, locked databases) without catching everything.
sqlite3.Error— base class for everything.sqlite3.DatabaseError— anything from inside the engine.sqlite3.IntegrityError— constraint violations (UNIQUE, NOT NULL, FK, CHECK).sqlite3.OperationalError— operational issues (locked, malformed, disk full).sqlite3.ProgrammingError— usage errors (closed cursor, wrong number of params).sqlite3.InterfaceError— driver-side problems before SQLite saw the call.
Tip:
except sqlite3.IntegrityError is how you idiomatically handle 'duplicate key' for an INSERT that may collide. Combined with UPSERT (track 4), most apps end up with very few catch sites.