3 ms·
Optional<T> isn't a replacement for typed exceptions as you can't pass or inspect the error details.
by jayd16 6y ago
Optional<T> isn't a replacement for typed exceptions as you can't pass or inspect the error details.
- rovolo 6y agoThat's correct. I used Optional because it's included in Java and it's simpler. With Optional I could explain handling the presence of errors, but not the inspection of errors. A full replacement is the Result type (a specialized 'Either'): https://doc.rust-lang.org/std/result/ https://doc.rust-lang.org/std/result/
- jayd16 6y agoYeah. Although, that has an explicit error type which is good and bad. The errors are consistent and known but you're restricted to throwing them together into a single type. I kind of like C#'s Task type where you can still use the catch block pattern matching if you want to. Maybe dropping the catch syntax is better though.