Hi Sven,

On Mon, Mar 1, 2021 at 8:59 PM Sven R. Kunze <srkunze@mail.de> wrote:

Hey Irit,

cool proposal.


Thank you.
 

I just have two questions regarding "except Exception" or "except BaseException" as it is used e.g. by concurrent.futures.process (def _process_worker) from the stdlib.

Almost similarly, I maintain a library using this pattern to wrap/unwrap exceptions from remote Python processes to create nicely formatted tracebacks (also recursively of course if needed) at the calling python process.

Usually these exceptions are wrapped, transferred to the parent process, there is the current call stack added, then reraised as a different exception, and so on and so forth if a chain of parents exist. The outermost parent process takes care of printing the tb.


My two questions regarding PEP 654:


1) What is the right "except pattern" when ExceptionGroup is introduced for the use cases described above (remote or concurrent python processes)?

 
If you want to catch the whole ExceptionGroup and format its traceback, then you can just do "except ExceptionGroup as eg" and then traceback.print_exception(eg).

The except* syntax is for when you want to handle only certain types of exceptions from the group, selectively.
 

2) What is the recommended approach of printing the traceback potentially incorporating multiple tracebacks - I couldn't find it in the PEP and tracebacks are a really neat tool for error hunting.


Part of the proposal of the PEP is that we teach the builtin traceback formatting code to display ExceptionGroups with all that information. The reference implementation has this, and the examples in the PEP were produced with it. Some of the examples (the early ones) show exceptions that were never raised so there is no traceback. But if you scroll down to the later examples, you see the output for exceptions with tracebacks, cause, context etc.

We didn't put too much effort into making the traceback output pretty, so at the moment it's a draft. If there is an ascii artist out there who has suggestions on improving this, that would be great.

Irit