3 ms·
The basic idea is that an exception is just data, so you can just treat it as part of the return type. Most of the rest of it is constructs that make it easy to
by moomin 2y ago
The basic idea is that an exception is just data, so you can just treat it as part of the return type. Most of the rest of it is constructs that make it easy to work with, which mostly means making things behave similarly to the way exceptions work. But with the option to just treat it as regular data rather than complex catch try rethrow logic.
Checked exceptions were inferior to this because they was outside of the type system; saying “This type or three possible exceptions” was so painful people stopped using. With this approach it’s just a type and has whatever name you like.
- Expurple 2y ago> “This type or three possible exceptions” was so painful people stopped using. A reader on Reddit has also pointed out [1] that it's literally impossible to represent "n possible exceptions" generically. Java makes you manually write out exactly 3 exceptions in the signature, or exactly 1 exception in the signature, or exactly 0 exceptions in the signature... [1] https://www.reddit.com/r/rust/comments/1h3kdye/rust_solves_the_issues_with_exceptions/lzsnn7g/ https://www.reddit.com/r/rust/comments/1h3kdye/rust_solves_t...