---
title: "Chapter 12: Error Handling"
description: "The 7 lessons of chapter 12: Error Handling, in teaching order."
url: "https://learnrust.net/chapter-12/"
last_updated: "2026-06-13"
---

# Chapter 12: Error Handling

- [12.1 panic! and unrecoverable errors](https://learnrust.net/chapter-12/panic-and-unrecoverable-errors.md): What panicking actually does, reading a backtrace with RUST_BACKTRACE, and assert!/debug_assert! as the panic machinery behind checked assumptions.
- [12.2 Result and recoverable errors](https://learnrust.net/chapter-12/result.md): Result<T, E> is the enum for operations that can fail; match on it, and understand unwrap and expect as deliberate convert-to-panic choices.
- [12.3 Propagating errors: the ? operator](https://learnrust.net/chapter-12/propagating-errors-question-mark-operator.md): The ? operator turns pages of match-on-Result boilerplate into one character: it returns the error early on Err and unwraps the value on Ok.
- [12.4 Handling invalid input properly](https://learnrust.net/chapter-12/handling-invalid-input.md): Turning the guessing game's expect crash into a polite retry loop, and a taxonomy of the ways user input goes wrong: malformed, out of range, and absent.
- [12.5 When to panic and when to return Result](https://learnrust.net/chapter-12/when-to-panic.md): Guidelines for choosing between panic and Result: expected versus exceptional, contracts, library versus application code, and when unwrap is fine.
- [12.6 Custom error types: a first look](https://learnrust.net/chapter-12/custom-error-types.md): Building error types as enums so callers can inspect what went wrong, implementing Display, and the Box<dyn Error> escape hatch for when you just want errors to flow.
- [12.x Chapter 12 summary and quiz](https://learnrust.net/chapter-12/chapter-12-summary-and-quiz.md): Review of panic, Result, the ? operator, handling invalid input, when to panic, and custom error types, with a chapter quiz and a capstone program.

## Sitemap

See the full [sitemap](https://learnrust.net/sitemap.md) for all pages.
