Rust error handling: Result, Option and the ? operator

10 steps · about 3 h 35 min · Intermediate

  1. Error Handling - The Rust Programming Language (doc, doc.rust-lang.org (The Rust Book), 5 min)

    It starts with the big idea that Rust has no exceptions, only Result for recoverable errors and panic! for unrecoverable ones.

  2. Recoverable Errors with Result - The Rust Programming Language (doc, doc.rust-lang.org (The Rust Book), 30 min)

    The official explanation of matching on Result, unwrap, propagating errors, and the ? operator with its From conversion.

  3. Rust Result (tutorial, rusttutorial.org, 20 min)

    A short second explanation of Ok, Err and ?, followed by a practice exercise that has you add two parsed numbers with ?.

  4. Option and Result · Learn Rust (interactive, learningrust.org, 30 min)

    It covers Option and Result combinators and shows the compiler error you get when you use ? on an Option inside a Result function.

  5. Rust error handling - Result, the ? operator, and custom errors (tutorial, zetcode.com, 20 min)

    Runnable examples of ? with Option, ok and ok_or conversions, and returning Result from main.

  6. Result - Rust By Example (doc, doc.rust-lang.org (Rust By Example), 15 min)

    Short, editable examples that show Result as a richer Option and how parse failures flow through main.

  7. To panic! or Not to panic! - The Rust Programming Language (doc, doc.rust-lang.org (The Rust Book), 15 min)

    Once you can use Result, this chapter teaches you when to return it and when a panic is acceptable.

  8. Rust Error Handling with anyhow and thiserror (tutorial, rusttutorial.org, 25 min)

    It introduces the two main error crates: thiserror for defining error types and anyhow for passing errors up with context.

  9. Error Handling in Rust: Result, ?, anyhow, and thiserror (article, blog.teliaz.com, 15 min)

    A decision guide that ties ?, From conversions, typed library errors and application context together.

  10. Error Handling In Rust - A Deep Dive (article, Luca Palmieri (lpalmieri.com), 40 min)

    It ends the list by questioning the simple rule that thiserror is for libraries and anyhow is for applications, with a framework for deciding who needs to see an error.