Module 6Robust ErrorsLesson 2 of 820 min
Custom Error Enums
Typed errors you can match on.
Enum errors
rust
#[derive(Debug)]
enum PricingError {
NonPositiveTime,
NonPositiveVol,
InvalidSpot,
}Callers match and decide UX vs retry.
Offline: implement Display + Error traits.
Challenge
Add InvalidStrike; wire a fake bs_call -> Result.
Tips
- Match error variants
- Keep enums clear
- thiserror helps offline
Try it live
Custom Error EnumsRust 2021
Loading editor…
Output
Press Run to compile and execute.