Skip to content
← All tracks

Errors Are Values

Rust

Replace exceptions with types: `Option`, `Result`, `?` as a `From` conversion, error enums, `Display`/`Error` by hand, and when a panic is the correct answer.

This track is written for Rust, which isn't the mode you're browsing in.

0 / 19 solved · 5 articles
  1. 1. No null, no exceptions: Option and Result are just enums Read
  2. 2. Not solved yet. Matching on Option
  3. 3. Not solved yet. The Option combinator vocabulary
  4. 4. Not solved yet. Eager vs lazy defaults
  5. 5. Not solved yet. Borrowing through Option
  6. 6. Not solved yet. Mutating an Option in place
  7. 7. Not solved yet. Result, and why it is #[must_use]
  8. 8. Not solved yet. Result combinators and map_err
  9. 9. Not solved yet. Converting between Option and Result
  10. 10. The `?` operator, exactly Read
  11. 11. Not solved yet. Propagating with `?`
  12. 12. Not solved yet. `?` on Option, and bridging to Result
  13. 13. When panic! is correct, and when it is a bug Read
  14. 14. Not solved yet. Implementing std::error::Error
  15. 15. Not solved yet. From impls: the machinery behind `?`
  16. 16. Not solved yet. Error chains and source()
  17. 17. Error enums vs Box<dyn Error> Read
  18. 18. Not solved yet. Boxed errors and downcasting
  19. 19. Not solved yet. Adding context without anyhow
  20. 20. What thiserror and anyhow actually generate Read
  21. 21. Not solved yet. #[must_use] in depth
  22. 22. Not solved yet. Collecting an iterator of Results
  23. 23. Not solved yet. unwrap and expect discipline
  24. 24. Not solved yet. Documenting failure: # Errors and # Panics

Check yourself

4 questions · one attempt each

These do not count toward finishing the track. They are here to catch the things that are easy to read past.

0 / 4

parse::<i32>() returns Result<i32, ParseIntError>, but the function returns Result<i32, MyErr>. Why does ? compile?

impl From<ParseIntError> for MyErr {
    fn from(e: ParseIntError) -> Self { MyErr(format!("wrapped: {e}")) }
}

fn parse(s: &str) -> Result<i32, MyErr> {
    Ok(s.parse::<i32>()? * 2)
}
Question 1 of 4