Skip to content

Commit

Permalink
Unwrap RTE in transaction to make it easier to handle SQLExceptions.
Browse files Browse the repository at this point in the history
  • Loading branch information
seancorfield committed Jul 25, 2011
1 parent 3daaca3 commit 758512c
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/main/clojure/clojure/java/jdbc/internal.clj
Expand Up @@ -178,7 +178,15 @@
result)
(catch Exception e
(.rollback con)
(throw e))
;; This ugliness makes it easier to catch SQLException objects
;; rather than something wrapped in a RuntimeException which
;; can really obscure your code when working with JDBC from
;; Clojure... :(
(letfn [(throw-non-rte [ex]
(cond (instance? java.sql.SQLException ex) (throw ex)
(and (instance? RuntimeException ex) (.getCause ex)) (throw-non-rte (.getCause ex))
:else (throw ex)))]
(throw-non-rte e)))
(finally
(rollback false)
(.setAutoCommit con auto-commit)))))
Expand Down

0 comments on commit 758512c

Please sign in to comment.