4 ms·
TL;DR: It's Java's explicit throw declarations with extra steps, and syntactic sugar to make the totally-not-exceptions work kinda like exceptions.
by mike_hock 3y ago
TL;DR: It's Java's explicit throw declarations with extra steps, and syntactic sugar to make the totally-not-exceptions work kinda like exceptions.
- pornel 3y agoIt does feel like checked exceptions. But the subtle but important thing is that results are not control flow constructs. They're just values with syntax sugar, so all other language features work with them (you can store, modify, nest, pass them without try/catch/throw constructs)
- mike_hock 3y agoIt's not subtle in that it's not opaque to the programmer that it's just a "regular" sum type It's not important in that it doesn't change what the programmer can do with it, it just changes the syntax used. Return an error: return Err(...) vs. throw ... Propagate error to caller: ? vs. nothing Store/modify/nest/pass: Without try/catch/throw construct vs. WITH try/catch/throw construct. The much more important difference is between bounded vs. unbounded error types. Rust falls in the former camp and inherits all the problems (and benefits) that come with it.
- pornel 3y agoI'm not sure what you mean by bounded. There's `dyn Error` that lets you unify all error types. You can also make functions generic over the error type. Places where people use precise concrete error types are not forced by the language, it's just the best practice for libraries.