4 ms·
Rust is one of the few languages I've seen that really does error handling right. Errors are still values in Rust - usually as part of the `Result` type - but
by realharo 4y ago
Rust is one of the few languages I've seen that really does error handling right.
Errors are still values in Rust - usually as part of the `Result` type - but unlike Go, it actually has tools to let you deal with them in a convenient way, like the `?` propagation operator (https://doc.rust-lang.org/book/ch09-02-recoverable-errors-with-result.html#a-shortcut-for-propagating-errors-the--operator https://doc.rust-lang.org/book/ch09-02-recoverable-errors-wi...), or the functions on the `Result` type like `map`, `and_then`, `map_err`, or crates like `thiserror` for defining error types, and `anyhow` for easily converting them when you don't care about the details.
- rjh29 4y agoThe fact that the anyhow/thiserror crates are basically required, or you have to make a bespoke enum for your crate's errors and write conversion functions for them, is not great. The try operator and Result type is amazing though.
- realharo 4y agoMany languages have this discussion about what functionality belongs in the standard library and what is best left to external libraries - to avoid being stuck with a bad design forever because of backwards compatibility, etc. I don't see a problem with relying on a few super popular basic libraries for almost every project.