On Sat, 27 Feb 2021 at 00:35, Guido van Rossum <guido@python.org> wrote:
On Fri, Feb 26, 2021 at 3:18 PM Marco Sulla <Marco.Sulla.Python@gmail.com> wrote:
Excuse me if I post here. Maybe is a stupid question: why, instead of introducing except*, Python can't extend the functionality of except, so it can do what except* would do?
Good question. Here's an example: ``` try: . . . except OSError as err: if err.errno != ENOENT: raise . . . ``` If this would catch ExceptionGroup(OSError), the `err` variable would be an ExceptionGroup instance, which does not have an `errno` attribute.
Thank you for the clarification :) I must admit I read the PEP quickly, so I thought that the subexception will be raised by except*, not the exception group. But obviously this can't work. The fact is I am really used to think that except OsError as e means "except for any OsError, which we name `e` from this moment on" that I thought it applied also for except*. But, if I understood well except* OsError as eg means "except for any OsError contained in an ExceptionGroup. If the OsError is not contained in an ExceptionGroup, Python wraps it in a new ExceptionGroup. The ExceptionGroup is named `eg` from this moment on" I have to say that it's not obvious for me reading except* this way. Anyway, I can't find a more readable semantic that does not use a new keyword and it's short ^^'