(defn method-with-exception []
(try
(throw (ex-info "test exception" {:step 1}))
(catch Exception e
;; 实现任意部分处理,
;; 并把错误传给调用方代码
(println "partial processing of" (ex-data e))
(throw e))))
(try
(method-with-exception)
(catch Exception e
(println "Exception:" (ex-message e))))
;; 或者包装它,把原异常保留为原因
(try
(try
(method-with-exception)
(catch Exception e
(throw (ex-info "wrapped" {} e))))
(catch Exception e
(println (ex-message e) "<-" (ex-message (ex-cause e)))))