Skip to content

Commit

Permalink
pythongh-98172: mention that except* handles naked exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
iritkatriel committed Oct 20, 2022
1 parent 4ec9ed8 commit 6fddcf8
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion Doc/reference/compound_stmts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ the case of :keyword:`except`, but in the case of exception groups we can have
partial matches when the type matches some of the exceptions in the group.
This means that multiple :keyword:`!except*` clauses can execute,
each handling part of the exception group.
Each clause executes once and handles an exception group
Each clause executes at most once and handles an exception group
of all matching exceptions. Each exception in the group is handled by at most
one :keyword:`!except*` clause, the first that matches it. ::

Expand All @@ -364,10 +364,23 @@ one :keyword:`!except*` clause, the first that matches it. ::
| ValueError: 1
+------------------------------------


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

If the exception raised inside the try body is not of type :exc:`ExceptionGroup`
or :exc:`BaseExceptionGroup`, and its type matches one of the :keyword:`!except*`
clauses, it is caught and wrapped by an exception group with an empty message
string. ::

>>> try:
... raise BlockingIOError
... except* OSError as e:
... print(repr(e))
...
ExceptionGroup('', (BlockingIOError()))

An :keyword:`!except*` clause must have a matching type,
and this type cannot be a subclass of :exc:`BaseExceptionGroup`.
It is not possible to mix :keyword:`except` and :keyword:`!except*`
Expand Down

0 comments on commit 6fddcf8

Please sign in to comment.