Exception Groups
Python 3.11 introduced ExceptionGroup and except* to handle multiple exceptions simultaneously — useful in async code.
Python 3.11 introduced ExceptionGroup and except* to handle multiple exceptions simultaneously — useful in async code.
try:
raise ExceptionGroup("errors", [
ValueError("bad value"),
TypeError("wrong type"),
])
except* ValueError as eg:
print("Value errors:", eg.exceptions)
except* TypeError as eg:
print("Type errors:", eg.exceptions)
ExceptionGroup is designed for concurrent tasks that raise multiple errors.