RosettaCodeData/Task/Exceptions-Catch-an-exception-thrown-in-a-nested-call/Clojure/exceptions-catch-an-exception-thrown-in-a-nested-call.clj
2023-07-01 13:44:08 -04:00

17 lines
337 B
Clojure

(def U0 (ex-info "U0" {}))
(def U1 (ex-info "U1" {}))
(defn baz [x] (if (= x 0) (throw U0) (throw U1)))
(defn bar [x] (baz x))
(defn foo []
(dotimes [x 2]
(try
(bar x)
(catch clojure.lang.ExceptionInfo e
(if (= e U0)
(println "foo caught U0")
(throw e))))))
(defn -main [& args]
(foo))