12
Error Handling
Error handling is an application’s ability to respond to exceptional events. Your program can take either a proactive or reactive posture to error handling. Proactive error handling is where error conditions are anticipated in program logic and then handled in some manner. Reactive error handling is responding to, and handling, if possible, problems after they occur.
For proactive error handling, Rust standardizes around the Result and Option types. These types help source code respond in a predictable and extensible manner to potential error results. This model is especially important for libraries. Libraries have a contract with callers to behave in a predictable manner.
For reactive error handling, Rust has panics. Panics ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access