4 ms·
I only "partially agree": I often wrap entire sections of a program in a try block. This way, it can catch any unexpected errors, report them, and put the progr
by fnl 9y ago
I only "partially agree": I often wrap entire sections of a program in a try block. This way, it can catch any unexpected errors, report them, and put the program back into a manageable state where it can keep running.
So I think exceptions are a good thing for unexpected outcomes; Resource errors, programming errors, etc. The problem is, we use them in cases where the error is, technically speaking, a possible, or "expect-able", outcome (such as the classical example of de-serializing data). In those cases, I fully agree, a type-level, explicit handler using the Either monad would be better.
I even think, the "expected case" is why Java introduced the notion of annotating exceptions. But as there are two different use-cases, this did not mix well...
- AstralStorm 9y agoOften, an error state machine is better than error code passing. (along the result or separately) Such a design forces you to handle all errors near the place they occurred without the syntactic overhead. (Threading problems are overrated. Easy to dodge by providing a Context attribute which then works like IO monad in Haskell.) It essentially works like exceptions without a forced stack unwind and return - which may or may not be good. Both are easy to convert and interoperate.