Step Into Labs

Step Into Rust · Lesson 6 · Robust Rust

Error Handling

Result, match, the ? operator, error messages and exit codes.

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

Missions

  1. match on a Result
  2. Your own error messages
  3. The ? operator
  4. A real command-line filter