In this chapter, we'll take a look at how fallible and unexpected situations are handled in Rust, gain an understanding of the error handling with errors as types, and look at how to design interfaces that compose well with error types. We aim to cover the first two error scenarios as they are under our control and languages generally provide mechanisms for handling these errors. If fatal errors occur, our program gets aborted by the operating system kernel and so we don't have much control over them.
In this chapter, we will cover the following topics:
- Error handling prelude
- Recovering from errors using the Option and Result types
- Combinator methods for Option and Result
- Propagating errors
- Non-recoverable errors
- Custom errors and the Error trait