3 ms·
Disclaimer: takes this with a grain of salt as I do use Box<dyn Error>. But I have a couple of things to note. 1. error chain is not the recommended way, despi
by swsieber 6y ago
Disclaimer: takes this with a grain of salt as I do use Box<dyn Error>. But I have a couple of things to note.
1. error chain is not the recommended way, despite being in the book. It needs updating!
2. The error trait in the std has come a long way since the book was originally written
3. You still might want some nicities that that Box<dun Error> doesn't provide you, and so you'd define an enum. You can do it manually, or use a library like anyhow or thiserror depending on if you're an app or library.
4. Rust error handling has been in a lot of flux, but generally improving. It probably does deserve a dedicated section in the book.
I recommend this blog post: https://nick.groenen.me/posts/rust-error-handling/ https://nick.groenen.me/posts/rust-error-handling/
- michael_j_ward 6y agoJust adding this video [0] that both gives a mental framework for designing errors and a "lay-of-the-land" for current libraries. Jane, the speaker, also heads up Rust's error handling project group [1], and gives her thoughts on future design / work. [0] https://www.youtube.com/watch?v=rAF8mLI0naQ https://www.youtube.com/watch?v=rAF8mLI0naQ [1] https://blog.rust-lang.org/inside-rust/2020/09/18/error-handling-wg-announcement.html https://blog.rust-lang.org/inside-rust/2020/09/18/error-hand...
- gsserge 6y ago> I recommend this blog post: https://nick.groenen.me/posts/rust-error-handling/ https://nick.groenen.me/posts/rust-error-handling/ This blog post is good indeed. The discussion on /r/rust linked at the end of the post is also worth reading. Another good and light introduction is http://www.sheshbabu.com/posts/rust-error-handling/ http://www.sheshbabu.com/posts/rust-error-handling/ And a more in-depth look https://blog.burntsushi.net/rust-error-handling/ https://blog.burntsushi.net/rust-error-handling/