Search code examples
sqlitecommon-lispsbclquicklisp

Catching errors from SQLite in Common Lisp


I'm using the SQLite wrapper from Quicklisp, which is described here. I notice that, for example, execute-non-query, returns nothing, but will throw sqlite-errors. However, I'm not sure how to handle them - as far as I can tell, catch needs an explicit tag, and I'm not sure how the wrapper tags them.

Basically, I would like to do something like this:

(if (no-error (execute-non-query *db* query-string))
    (do-happy-thing)
    (report-error))

How would I go about doing this?


Solution

  • handler-case is your friend.

    (handler-case 
        (progn
          (execute-non-query *db* query-string)
          (do-happy-thing))
      (sqlite-error (err) (report-error err))) ; err contains additional information