Re:Overview of Rust error handling libraries
by loeg on Friday November 22, 2019 @01:24PM
(#21608360)
As a Rust newbie, this is why I end up just using .unwrap() everywhere. result::Result, io::Result, is something a Some/None or an Ok/Error, etc, etc. What (non-string) errors does this function return, etc? I find it easier to check for and propagate integer error numbers correctly in C.
[ Parent
| on HN ]
Re:Overview of Rust error handling libraries
by pornel on Friday November 22, 2019 @05:18PM
(#21610721)
Use `Box<dyn Error>` as your error type, and you won't need to know about any other error type. They all convert automatically and propagate through the `?` operator.
failure and anyhow crates are `Box<dyn Error>` on steroids.
Re:Overview of Rust error handling libraries
by unlinked_dll on Friday November 22, 2019 @02:23PM
(#21609048)
One pattern is to use your own crate-level Error type and then Result::map_err to bubble up other error types into your own thing. Example:
https://play.rust-lang.org/?version=stable&mode=debug&editio...
This makes error handling a little more verbose but you can use some quick and dirty macros for that.
Re:Overview of Rust error handling libraries
by shepmaster on Friday November 22, 2019 @03:15PM
(#21609581)
> but you can use some quick and dirty macros for that.
That is the point of most of the libraries described in the article — to prevent having to recreate this particular wheel each time you need it. Do all Rust programs/libraries need one of the libraries? Not at all, but I find that using one that has some nice bells and whistles will encourage the programmer to improve the errors and their messages.