I am not sure whether error handling with monads is considered as best practice for Clojure but it seems quite popular (however, I still see exceptions to be used also a lot). Monads seem more functional approach to error handling. However, I am missing the stacktrace when using error monads. Is there a way how to get stacktrace when using monads? Or what is the alternative in here?
Stacktrace and error monads in Clojure
378 views Asked by Viktor K. At
2
There are 2 answers
0
On
Stack traces can be generated by saying (Exception. "msg")
anywhere. I have been working on Promenade (see documentation) that can combine exceptions and errors-as-values. You should take a look if that sounds like a potential solution.
As muhuk says, you'd use a monad to avoid getting a stacktrace.
An article I discovered when answering another SO recently that relates to the one you linked is http://overwatering.org/blog/2013/12/clojures-thread-for-monads
It builds a
m->
threading monad, and gives example of using it to produce afail->
monad based on the work in the error monads article. It allows you to effectively return different error types during execution.