spatialdude / usqlite

μSQLite library module for MicroPython
MIT License
87 stars 18 forks source link

Update the usqlite_Error class #30

Closed jandriea closed 2 months ago

jandriea commented 2 months ago

In the current implementation, the try/except statement cannot catch the _usqliteError unless we use a bare except

import usqlite

con = usqlite.connect("data.db")
try:
   con.execute("COMMIT;")
except:
   pass
con.close()

In this update, I added the Exception type as the parent class of the _usqliteError. So, we can catch the exception as Exception type

import usqlite

con = usqlite.connect("data.db")
try:
   con.execute("COMMIT;")
except Exception as e:
   pass
con.close()

Additionally, I also added the usqlite_Error to the global objects so the user can catch the _usqliteError directly

import usqlite

con = usqlite.connect("data.db")
try:
   con.execute("COMMIT;")
except usqlite.usqlite_Error as e:
   pass
con.close()
spatialdude commented 2 months ago

Great work @jandriea This a very nice improvement. Thanks for your effort.