Please ignore performance issues, I am interesting in data flow, safety, modelling, reasoning.
I wonder what are the limitations of exception approach to error reporting implemented like in Java compared to Haskell-like (OCaml, and Rust use same/similar approach AFAIK).
As far as I know in both cases error is part of the function signature, but in Haskell you have to explicitly "handle" the error even if entire "handling" is just passing it further. I see a difference for the reader, in Java:
try
{
a = foo();
b = bar();
}
it is impossible to tell (just by looking at the code) if foo
and/or bar
can end up with error, also in both cases the error can be silently passed. If I understand correctly in Haskell the the counterpart code would be put into monad:
do a <- foo();
b = bar();
(I am new to Haskell, so forgive me the errors) and it is clear where the drop occurs and which line can fail.
BUT -- this is for human, compiler knows it in both cases.
So when it comes to, say, reasoning about the data flow (for compiler, not human), what are the limitations of Java approach? In other words, what is not doable in Java that is possible in Haskell? Or what information Haskell has which is not present in Java?