3 ms·
"Checked Exceptions" and the Result pattern can be translated back and forth by a machine (i.e. syntax sugar for each other). The trick is "Exceptions" are mor
by yazaddaruvala 10y ago
"Checked Exceptions" and the Result pattern can be translated back and forth by a machine (i.e. syntax sugar for each other).
The trick is "Exceptions" are more than just "Checked Exceptions"
- Retra 10y agoChecked exceptions probably act more like ad-hoc enums since you've got to handle each kind of exception that can be thrown, but I'm sure that could be encoded in nested results too.
- yazaddaruvala 10y agoFair enough, CheckedExceptions are almost always "fat pointers". Meaning they are all the same size, and can be passed around equivalently. The Rust equivalent would be something like: `Result<_, Box<Error>>`
- gpderetta 10y agoAmen, they have the same expressive power. The thing is that exceptions do not require the manual CPS transform required to handle Result objects, which results in nicer code. Even with syntactic sugar like do notation, the syntax is still different from 'normal' code. Also the escape hatch to unchecked exceptions is convenient too (then again Rust has some form of it already).