From ff59828fd2772024406ee031b68a57a48139b585 Mon Sep 17 00:00:00 2001 From: Irit Katriel Date: Thu, 20 Oct 2022 21:15:01 +0100 Subject: [PATCH 1/2] gh-98172: mention that except* handles naked exceptions --- Doc/reference/compound_stmts.rst | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Doc/reference/compound_stmts.rst b/Doc/reference/compound_stmts.rst index 8963481836431b..d8c4824d865213 100644 --- a/Doc/reference/compound_stmts.rst +++ b/Doc/reference/compound_stmts.rst @@ -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. :: @@ -364,10 +364,22 @@ 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 raised exception is not an exception group 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*` From 2942b9ded170c9067113526f274662d3035cd7de Mon Sep 17 00:00:00 2001 From: Irit Katriel <1055913+iritkatriel@users.noreply.github.com> Date: Fri, 21 Oct 2022 10:09:49 +0100 Subject: [PATCH 2/2] OSError --> BlockingIOError Co-authored-by: Jelle Zijlstra --- Doc/reference/compound_stmts.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/reference/compound_stmts.rst b/Doc/reference/compound_stmts.rst index d8c4824d865213..c3c78119958e79 100644 --- a/Doc/reference/compound_stmts.rst +++ b/Doc/reference/compound_stmts.rst @@ -375,7 +375,7 @@ exception group with an empty message string. :: >>> try: ... raise BlockingIOError - ... except* OSError as e: + ... except* BlockingIOError as e: ... print(repr(e)) ... ExceptionGroup('', (BlockingIOError()))