Обработка исключений

(defn throw-if-true [param]
  (try
    (when param
      (throw (ex-info "test exception" {})))
    (catch Exception e
      (println "catch"))
    (finally
      (println "finally"))))

(throw-if-true true)
;; printed: "catch" and "finally"
(throw-if-true false)
;; printed only "finally"

;; with-open is the idiom for a resource:
;; it calls .close even when the body throws
(with-open [w (java.io.StringWriter.)]
  (.write w "closed anyway")
  (println (str w)))