@@ -539,6 +539,30 @@ errors is error prone.
539539
540540We can consider allowing some of them in future versions of Python.
541541
542+ ## The Traceback of an Exception Group
543+
544+ For regular exceptions, the traceback represents a simple path of frames,
545+ from the frame in which the exception was raised to the frame in which it was
546+ was caught or, if it hasn't been caught yet, the frame that the program's
547+ execution is currently in. The list is constructed by the interpreter which,
548+ appends any frame it exits to the traceback of the 'current exception' if one
549+ exists (the exception returned by ` sys.exc_info() ` ). To support efficient appends,
550+ the links in a traceback's list of frames are from the oldest to the newest frame.
551+ Appending a new frame is then simply a matter of inserting a new head to the
552+ linked list referenced from the exception's ` __traceback__ ` field. Crucially,
553+ the traceback's frame list is immutable in the sense that frames only need to
554+ be added at the head, and never need to be removed.
555+
556+ We will not need to make any changes to this data structure. The
557+ ` __traceback__ ` field of the ExceptionGroup object represents that path that
558+ the exceptions travelled through together after being joined into the
559+ ExceptionGroup, and the same field on each of the nested exceptions represents
560+ that path through which each exception arrived to the frame of the merge.
561+
562+ What we do need to change is any code that interprets and displays tracebacks,
563+ because it will now need to continue into tracebacks of nested exceptions
564+ once the traceback of an ExceptionGroup has been processed.
565+
542566## Design Considerations
543567
544568### Why try..except* syntax
@@ -698,6 +722,16 @@ to start using the new `except *` syntax right away. They will have to use
698722the new ExceptionGroup low-level APIs along with ` try..except ExceptionGroup `
699723to support running user code that can raise exception groups.
700724
725+ ### Traceback Representation
726+
727+ We considered options for adapting the traceback data structure to represent
728+ trees, but it became apparent that a traceback tree is not meaningful once separated
729+ from the exceptions it refers to. While a simple-path traceback can be attached to
730+ any exception by a ` with_traceback() ` call, it is hard to imagine a case where it
731+ makes sense to assign a traceback tree to an exception group. Furthermore, a
732+ useful display of the traceback includes information about the nested exceptions.
733+ For this reason we decided it is best to leave the traceback mechanism as it is
734+ and modify the traceback display code.
701735
702736## See Also
703737
0 commit comments