Reputation: 7693
I use (try (/ 1 0) (catch Exception e))
but it seems redundant. Is there an easier way to do this?
An example where I'm use this is that I do sql/drop-table
. It doesn't matter if that call fails because the table doesn't exist.
Upvotes: 3
Views: 1662
Reputation: 34281
How about writing a macro like this:
(defmacro swallow-exceptions [& body]
`(try ~@body (catch Exception e#)))
(swallow-exceptions (/ 1 0)) ; nil
More sophisticated examples are in this post.
Upvotes: 9