Apologies I'm not a core dev so this might be the wrong place to ask but I have 2 small clarifying questions about the PEP.

Firstly, if I have a library which supports multiple versions of Python and I need to catch all standard exceptions, what is considered the best practise after this PEP is introduced?

Currently I might have code like this right now:
    ... # Code
except Exception as e:
    ... # Logic to handle exception

Reading through the PEP, particularly on backwards compatibility it looks like I would now need to do this:
except NameError:
    standard_exceptions = Exception
    standard_exceptions = (Exception, ExceptionGroup)

    ... # Code
except standard_exceptions as e:
    ... # Logic to handle exception
Secondly, once I only support versions of Python that support Exception groups, what replaces the best practise for generally catching standard exceptions? Is it this:
    ... # Code
except *Exception as e:
    ... # Logic to handle exception

Damian (He/Him)

On Mon, Feb 22, 2021 at 7:48 PM Irit Katriel via Python-Dev <python-dev@python.org> wrote:

Hi all,

We would like to request feedback on PEP 654 -- Exception Groups and except*.


It proposes language extensions that allow programs to raise and handle multiple unrelated
exceptions simultaneously, motivated by the needs of asyncio and other concurrency libraries,
but with other use cases as well.

* A new standard exception type,  ExceptionGroup, to represent multiple exceptions with
  shared traceback.
* Updates to the traceback printing code to display (possibly nested) ExceptionGroups.
* A new syntax except* for handling ExceptionGroups.

A reference implementation (unreviewed) can be found at:

Thank you for your help

Kind regards
Irit, Yury & Guido

Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-leave@python.org
Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/L5Q27DVKOKZCDNCAWRIQVOZ5DZCZHLRM/
Code of Conduct: http://python.org/psf/codeofconduct/