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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With