Step Into Rust · Lesson 6 · Robust Rust
Error Handling
Result, match, the ? operator, error messages and exit codes.
- ~35 minreading and coding
- 4missions
- membersaccess
- Rustlanguage
Part of Step Into Rust. The full lesson, its missions and the real compiler and debugger are in the course. Try a free lesson first to see how it works.
C functions report failure with special return values and errno, which are easy to ignore. Rust functions that can fail return Result<T, E>: either Ok(value) or Err(error). You cannot get at the value without deciding what happens on error.
In this lesson
- Errors are values
- unwrap and expect
- The ? operator
- Your own errors
- stdin, stderr and exit codes
Missions
- match on a Result
- Your own error messages
- The ? operator
- A real command-line filter