@@ -338,23 +338,28 @@ stored in the :mod:`sys` module is reset to its previous value::
338338The :keyword: `!except* ` clause(s) specify one or more handlers for groups of
339339exceptions (:exc: `BaseExceptionGroup ` instances). A :keyword: `try ` statement
340340can have either :keyword: `except ` or :keyword: `!except* ` clauses, but not both.
341- The exception type for matching is interpreted as in the case of
341+ The exception type for matching is mandatory in the case of :keyword: `!except* `,
342+ so ``except*: `` is a syntax error. The type is interpreted as in the case of
342343:keyword: `except `, but matching is performed on the exceptions contained in the
343- group that is being handled. Each :keyword: `!except* ` clause splits (see
344- :meth: `~BaseExceptionGroup.split `) the exception group into the subgroups of
345- matching and non-matching exceptions. If the matching subgroup is not empty, it
346- becomes the handled exception (the value returned from ``sys.exception() ``) and
347- assigned to the target of the :keyword: `!except* ` clause (if there is one). Then,
348- the body of the :keyword: `!except* ` clause is executed. If the non-matching
344+ group that is being handled. An :exc: `TypeError ` is raised if a matching
345+ type is a subclass of :exc: `BaseExceptionGroup `, because that would have
346+ ambiguous semantics.
347+
348+ When an exception group is raised in the try block, each :keyword: `!except* `
349+ clause splits (see :meth: `~BaseExceptionGroup.split `) it into the subgroups
350+ of matching and non-matching exceptions. If the matching subgroup is not empty,
351+ it becomes the handled exception (the value returned from ``sys.exception() ``)
352+ and assigned to the target of the :keyword: `!except* ` clause (if there is one).
353+ Then, the body of the :keyword: `!except* ` clause executes. If the non-matching
349354subgroup is not empty, it is processed by the next :keyword: `!except* ` in the
350- same manner. This continues until all exceptions in the group have been matched,
355+ same manner. This continues until all exceptions in the group have been matched,
351356or the last :keyword: `!except* ` clause has run.
352357
353- After the last :keyword: `!except* ` runs, and before the :keyword: `!finally ` block
354- (if there is one) executes, the group of unhandled exceptions is merged with
355- any exceptions that were raised or re-raised from within :keyword: `!except* `
356- clauses. This merged exception group propagates on.
358+ After all :keyword: `!except* ` clauses execute, the group of unhandled exceptions
359+ is merged with any exceptions that were raised or re-raised from within
360+ :keyword: `!except* ` clauses. This merged exception group propagates on.
357361
362+ and before the :keyword: `!finally `
358363 >>> try :
359364 ... raise ExceptionGroup(" eg" ,
360365 ... [ValueError (1 ), TypeError (2 ), OSError (3 ), OSError (4 )])
@@ -366,8 +371,10 @@ clauses. This merged exception group propagates on.
366371 caught <class 'ExceptionGroup'> with nested (TypeError(2),)
367372 caught <class 'ExceptionGroup'> with nested (OSError(3), OSError(4))
368373 + Exception Group Traceback (most recent call last):
369- | File "<stdin>", line 2, in <module>
370- | ExceptionGroup: eg
374+ | File "<doctest default[0]>", line 2, in <module>
375+ | raise ExceptionGroup("eg",
376+ | [ValueError(1), TypeError(2), OSError(3), OSError(4)])
377+ | ExceptionGroup: eg (1 sub-exception)
371378 +-+---------------- 1 ----------------
372379 | ValueError: 1
373380 +------------------------------------
@@ -384,12 +391,6 @@ type of the target ``e`` is consistently :exc:`BaseExceptionGroup`::
384391 ...
385392 ExceptionGroup('', (BlockingIOError()))
386393
387- An :keyword: `!except* ` clause must have a matching expression; it cannot be ``except*: ``.
388- Furthermore, this expression cannot contain exception group types, because that would
389- have ambiguous semantics.
390-
391- It is not possible to mix :keyword: `except ` and :keyword: `!except* `
392- in the same :keyword: `try `.
393394:keyword: `break `, :keyword: `continue ` and :keyword: `return `
394395cannot appear in an :keyword: `!except* ` clause.
395396
0 commit comments