Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Idiomatic error handling in 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?

like image 211
Emil Eriksson Avatar asked Jan 02 '15 12:01

Emil Eriksson


1 Answers

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.

like image 113
Symfrog Avatar answered Sep 24 '22 08:09

Symfrog