Skip to content
Prev Previous commit
Next Next commit
Add section headers to fix :keyword: role and aid navigation
  • Loading branch information
CAM-Gerlach committed Aug 14, 2022
commit 6a0721d427c92bfd66f853ca0e6d0a83c050aa10
14 changes: 14 additions & 0 deletions Doc/reference/compound_stmts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ for a group of statements:

.. _except:

:keyword:`!except` clause
-------------------------

The :keyword:`except` clause(s) specify one or more exception handlers. When no
Comment thread
CAM-Gerlach marked this conversation as resolved.
Outdated
exception occurs in the :keyword:`try` clause, no exception handler is executed.
When an exception occurs in the :keyword:`!try` suite, a search for an exception
Expand Down Expand Up @@ -311,11 +314,15 @@ when leaving an exception handler::
>>> print(sys.exc_info())
(None, None, None)


.. index::
keyword: except_star

.. _except_star:

:keyword:`!except*` clause
--------------------------

The :keyword:`except*<except_star>` clause(s) are used for handling
:exc:`ExceptionGroup`\ s. The exception type for matching is interpreted as in
Comment thread
CAM-Gerlach marked this conversation as resolved.
Outdated
the case of :keyword:`except`, but in the case of exception groups we can have
Expand Down Expand Up @@ -362,16 +369,23 @@ one except* clause, the first that matches it. ::

.. _except_else:

:keyword:`!else` clause
-----------------------

The optional :keyword:`!else` clause is executed if the control flow leaves the
:keyword:`try` suite, no exception was raised, and no :keyword:`return`,
:keyword:`continue`, or :keyword:`break` statement was executed. Exceptions in
the :keyword:`!else` clause are not handled by the preceding :keyword:`except`
clauses.


.. index:: keyword: finally

.. _finally:

:keyword:`!finally` clause
--------------------------

If :keyword:`finally` is present, it specifies a 'cleanup' handler. The
:keyword:`try` clause is executed, including any :keyword:`except` and
:keyword:`!else` clauses. If an exception occurs in any of the clauses and is
Expand Down