iGE*_*GEL 2 exception-handling exception clojure
这有点类似于这个问题,但我希望捕获多个异常并处理它们.在Ruby中,我可以写
begin
rand(2) == 0 ? ([] + '') : (foo)
rescue TypeError, NameError => e
puts "oops: #{e.message}"
end
Run Code Online (Sandbox Code Playgroud)
我可以在Clojure中做同样的事吗?现在我let是一个功能,只需在每个catch身体中调用它.
(ns mastering.stackoverflow
(:use
[slingshot.slingshot :only [try+]]))
(try+
; ...
(catch (comp #{TypeError NameError} class) _ "caught"))
Run Code Online (Sandbox Code Playgroud)
弹弓库可在github上找到.
| 归档时间: |
|
| 查看次数: |
222 次 |
| 最近记录: |