异常
处理异常
用try/catch/finally
来处理异常
user=> (try
#=> (/ 1 0)
#=> (catch Exception e
#=> (println "/ zero!!"))
#=> (finally
#_=> (println "finish!")))
/ zero!!
finish!
nil
抛出异常
用throw
抛出异常
(throw (Exception "something wrong !"))
异常数据
- 用
ex-info
携带一个字符串和一个map - 用
ex-data
可以获得map,如果map没有设置则返回nil
(try
(throw (ex-info "There was a problem" {:detail 42}))
(catch Exception e
(prn (:detail (ex-data e)))))