Rust Fundamentals interview question · Most asked
How does error handling work in Rust?
Summary
Recoverable errors are values of type Result<T, E>, handled with match or propagated with the ? operator; unrecoverable bugs panic. Option<T> represents absence instead of null.
Longer Answer
Libraries define error enums implementing Display and std::error::Error (often with thiserror); applications often use anyhow for context. ? converts errors via From.
Key Points
- Result + ? for expected failures.
- panic! for bugs.
- Custom error enums; thiserror/anyhow.
Deep dive: Rust Fundamentals: Error Handling