Skip to content

Commit 8367ca1

Browse files
authored
gh-98172: [doc] mention that except* handles naked exceptions (GH-98496)
1 parent 49f6106 commit 8367ca1

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

Doc/reference/compound_stmts.rst

+13-1
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ the case of :keyword:`except`, but in the case of exception groups we can have
343343
partial matches when the type matches some of the exceptions in the group.
344344
This means that multiple :keyword:`!except*` clauses can execute,
345345
each handling part of the exception group.
346-
Each clause executes once and handles an exception group
346+
Each clause executes at most once and handles an exception group
347347
of all matching exceptions. Each exception in the group is handled by at most
348348
one :keyword:`!except*` clause, the first that matches it. ::
349349

@@ -364,10 +364,22 @@ one :keyword:`!except*` clause, the first that matches it. ::
364364
| ValueError: 1
365365
+------------------------------------
366366

367+
367368
Any remaining exceptions that were not handled by any :keyword:`!except*`
368369
clause are re-raised at the end, combined into an exception group along with
369370
all exceptions that were raised from within :keyword:`!except*` clauses.
370371

372+
If the raised exception is not an exception group and its type matches
373+
one of the :keyword:`!except*` clauses, it is caught and wrapped by an
374+
exception group with an empty message string. ::
375+
376+
>>> try:
377+
... raise BlockingIOError
378+
... except* BlockingIOError as e:
379+
... print(repr(e))
380+
...
381+
ExceptionGroup('', (BlockingIOError()))
382+
371383
An :keyword:`!except*` clause must have a matching type,
372384
and this type cannot be a subclass of :exc:`BaseExceptionGroup`.
373385
It is not possible to mix :keyword:`except` and :keyword:`!except*`

0 commit comments

Comments
 (0)