Loading lesson…
Level 1 · Apprentice0 XP
Exceptions, require and check, Result, and sealed results for expected failures.
Step 1 / 5
ProblemLogin throws UserNotFoundException, WrongPasswordException and AccountLockedException. Callers wrap everything in try-catch, and one forgotten catch crashes the screen.
← → step
Before this: Sealed classes and when
🛠️ Your turn
Reading is not the skill, doing is. Try for ten minutes before you open the hint. Getting stuck first is what makes the solution stick.
1.Rewrite a function that throws three different exceptions for expected outcomes into one returning a sealed result. Update callers to use an exhaustive when, and keep exceptions only for real failures.