问题描述
当我戴上我的帽子,我认为,惯用的Clojure只是做简单的事情,并检查返回值。
当我戴上我的Java帽子(不情愿,我必须添加),我想自己,因为Clojure在JVM上运行,自然的方式必须使用JVM异常。
当我戴上我的功能帽时,我认为必须有某种monadic构造或线程宏可以以可组合的方式处理错误。 / p>
那么,在Clojure程序中处理错误的惯用方法是什么?
p> Clojure错误处理通常是JVM异常(未检查)导向。
可让异常更愉快,例如允许解构抛出异常值。
对于允许erlang风格错误处理的替代方法,您应该查看。此可以很好地概述理性的恐惧以及Clojure错误处理机制和缺点的概述。
When I put on my C hat, I think that maybe idiomatic Clojure just does the simple thing and checks return values.
When I put on my Java hat (reluctantly, I must add), I think to myself that since Clojure runs on the JVM the natural way must be to use JVM exceptions.
When I put on my functional hat, I'm thinking that there must be some sort of monadic construction or threading macro that can handle errors in a composable way.
So what's the idiomatic way to handle errors in a Clojure program?
Clojure error handling is generally JVM exception (unchecked) oriented.
Slingshot makes using exceptions more pleasant by allowing, for example, destructuring on thrown exception values.
For an alternative that allows erlang-style error handling you should look at dire. This blog post gives a good overview of the rational for dire as well as an overview of Clojure error handling mechanisms and drawbacks.
这篇关于Clojure中的惯用错误处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!