I would like to share something that I've learned the hard way, developing google-drive-ocamlfuse. When mixing monadic programming and exception  handling, you have to be extra careful. In fact, when you deal with a lot of partially applied functions, there is the risk that your try/with block does not wrap a fully applied function, and the exceptions that may be thrown can slip outside the exception handler. I've prepared a gist, where I show the problem and how to resolve it (obviously the solution requires one more level of indirection. :-) Hope this is useful.
Lukasz Stafiniak's profile photoAlessandro Strada's profile photoPaolo Donadeo's profile photo
I think it is more a problem of mixing within-monad and outside-monad constructs. If you use an equivalent of Lwt's try_bind you shouldn't have problems, no? In other words, if you work with monads, you need an exception monad transformer.
Yes, you are right, in fact the problem arises because in OCaml there is not an easy way to stack monads, and moreover any function may raise an exception, so you are always "inside" the Error monad.
Add a comment...