### Macros to deal with exceptions
(silence target expr)
(silence substitute target expr)
Returns substitute
if expr
raises an exception that matches
target
.
If not provided, substitute
is nil
.
Target can be:
(silence ArithmeticException (/ 1 0))
=> nil
(silence "Divide by zero" (/ 1 0))
=> nil
(silence [ArithmeticException]
(do (println "watch out !")
(/ 1 0)))
;; watch out !
=> nil
(silence :substitute
(fn [x]
(isa? (class x) ArithmeticException))
(/ 1 0))
=> :substitute
Returns `substitute` if `expr` raises an exception that matches `target`. If not provided, `substitute` is `nil`. Target can be: - a class - a sequence of classes - a predicate - a string ```clojure (silence ArithmeticException (/ 1 0)) => nil (silence "Divide by zero" (/ 1 0)) => nil (silence [ArithmeticException] (do (println "watch out !") (/ 1 0))) ;; watch out ! => nil (silence :substitute (fn [x] (isa? (class x) ArithmeticException)) (/ 1 0)) => :substitute ```
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close