I was sent this snippet of Python:
try:
raise ExceptionGroup('group', [ValueError(123)])
except* ValueError:
print('Handling ValueError')
What does except* do?
I was sent this snippet of Python:
try:
raise ExceptionGroup('group', [ValueError(123)])
except* ValueError:
print('Handling ValueError')
What does except* do?
except* is the new syntax for "Exception Groups" that will be added in Python 3.11.
See PEP 654 (specifically this section) for more details.
In brief, it captures one or more ValueError exceptions that may be part of a raised ExceptionGroup, without preventing additional except* clauses from handling other exceptions in the same group.