123
The Compiler Is Your Best Friend, Stop Lying to It - Daniel Beskin's Blog
(blog.daniel-beskin.com)
Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!
Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.
Hope you enjoy the instance!
Rules
Follow the wormhole through a path of communities !webdev@programming.dev
You can use the
anyhowcrate for something quite similar to exceptions: https://crates.io/crates/anyhowIn terms of how it actually fits into Rust, you want to use
anyhowfor application code. If you're writing a library, thenanyhowis a no-go, because users cannot match on different error classes with it. (Much like you would want custom exception classes, so that users can catch them in different catch branches and handle them differently.)Every so often, you will also need matchable error classes within your application code, then you would have to replace
anyhowwith a custom error type there, too, of course.I will also say, IMHO it is fine to use
anyhoweven while you're learning Rust. It is so easy that you kind of skip learning error handling, which you will need to learn at some point, but you can still do that when you actually need it.