Skip to main content
🔒 Preview mode. The first 15 Foundations lessons are free; this one is Pro. Start a 7-day trial to unlock the editor, AI hints and the rest of the curriculum. Card required, cancel any time in Dashboard.Start 7-day trial →
← CoursesSenior Deep-DivesModule 9 · Error handling depthExceptionGroup + except* — multiple failures, one raisepredict139 / 161
+150 XP
Task
📝 **Task:** Predict the 6-line output. The validator raises an ExceptionGroup containing 3 leaves: 2 ValidationErrors and 1 TypeError. Two `except*` clauses partition the group by type and print what they caught. 📋 Implement the function above. Tests run automatically. 💡 **Hint:** Re-read the theory if you get stuck.
Predict the output

Read the code carefully

class ValidationError(Exception):
    pass


errors: list[Exception] = [
    ValidationError("email is invalid"),
    ValidationError("password too short"),
    TypeError("age must be int"),
]


try:
    raise ExceptionGroup("validation failed", errors)
except* ValidationError as eg:
    print(f"caught {len(eg.exceptions)} validation errors")
    for e in eg.exceptions:
        print(f"  - {e}")
except* TypeError as eg:
    print(f"caught {len(eg.exceptions)} type errors")
    for e in eg.exceptions:
        print(f"  - {e}")

What will the program print? Write here:

💬 Discussion

Be the first to ask a question or share a tip.
Sign in to join the discussion. Reading is free.
Loading discussion…