Curriculum Errors, crates & tests Custom error enums exercise 3 · mcq
Custom error enums
Inside a function returning Result<i32, AppError>, calling
s.parse::<i32>() produces a Result<i32, ParseIntError>. You
want ? to convert the ParseIntError into an AppError
automatically. Pick the mechanism.
About this theme
Small Rust programs often use an enum for domain errors. This theme teaches error variants, carrying context, Display, and using From so ? can convert lower-level errors. Planned exercises: 1. choose an error enum. 2. recognise context-carrying variants. 3. choose From for conversion. 4. fill an Err(MyError::...). 5. fill a Display arm. 6. write a domain error enum. 7. write a conversion with From. 8. translate TS custom error classes. 9. fix an error propagation type mismatch.