4 ms·
I actually think checked exceptions make handling error propagation much easier than Option types. In a language with checked exceptions, if you want to propaga
by shawnz 8y ago
I actually think checked exceptions make handling error propagation much easier than Option types. In a language with checked exceptions, if you want to propagate the error, all you have to do is declare that intent. With Option types, there is a need for boilerplate unwrapping code in almost every place where you want to use the value.
- kaoD 8y ago> With Option types, there is a need for boilerplate unwrapping code in almost every place where you want to use the value. Disagree, in my favorite language you just add "?" to the possibly-erroring function et voilá, error propagated. Even better, since errors are functor-like (map) and monad-like (and_then), I'm mostly never unwrapping myself. This has the advantage that it's explicit, instead of exceptions implicitly returning early (sometimes to great amusement).
- Faark 8y ago> Disagree, in my favorite language you just add "?" to the possibly-erroring function et voilá, error propagated And one of the first things I had to learn in rust was how make this happen with different error types. After that it was pretty much the same as exceptions. What functions return errors is a little more obvious, at the cost of extra boiler plate (most stuff being Result<...> anyway) Checked exceptions Java style could be a perfect balance with just a few modifications. Compiler/IDE should mostly know whats thrown where, so specifying it manually should rarely be necessary. And still could visualize what can fail and with what errors.