except*
for regular exceptions
There is one more thing you should know about except*
. It can match not only sub-exceptions from ExceptionGroup
but regular exceptions too. And for simplicity of handling, regular exceptions will be wrapped into ExceptionGroup
:
try:
raise KeyError
except* KeyError as e:
print('caught:', repr(e))
# caught: ExceptionGroup('', (KeyError(),))