top | item 40831382

(no title)

rpbiwer2 | 1 year ago

I can't cite my sources, but I recently started learning Rust and I've been doing this. I would guess that I picked it up from the Rust book, since that's been my primary learning source.

I know I _could_ define my own error type, but that's tedious, especially if there are many types of errors to handle. For my (non-production) purposes it's been fine.

What's the idiomatic way to handle errors? Is there a way to collect more detailed error information without excessive boilerplate?

discuss

order

steveklabnik|1 year ago

A common but of advice is “use anyhow for applications and thiserror for libraries” but what it really boils down to is, anyhow is good for handling errors, and thiserror is good for defining your own error types.

The docs have good examples of basic usage: https://docs.rs/anyhow/latest/anyhow/