diff --git a/Doc/reference/simple_stmts.rst b/Doc/reference/simple_stmts.rst --- a/Doc/reference/simple_stmts.rst +++ b/Doc/reference/simple_stmts.rst @@ -463,11 +463,18 @@ is invoked, the function can proceed exactly as if the :keyword:`yield` statement were just another external call. -The :keyword:`yield` statement is allowed in the :keyword:`try` clause of a -:keyword:`try` ... :keyword:`finally` construct. If the generator is not -resumed before it is finalized (by reaching a zero reference count or by being -garbage collected), the generator-iterator's :meth:`close` method will be -called, allowing any pending :keyword:`finally` clauses to execute. +The :keyword:`yield` statement is allowed in the :keyword:`try` clause +of a :keyword:`try` ... :keyword:`finally` construct. If the generator +is not resumed before it is finalized (by reaching a zero reference +count or by being garbage collected), the generator-iterator’s +:meth:`close` method will be called, and the :keyword:`yield` +statement in the generator function will raise :exc:`GeneratorExit`. + +If a generator function raises :exc:`GeneratorExit` (either directly +or by not catching it), future calls to the :meth:`next` method of the +generator iterator will raise :exc:`StopIteration`. +:exc:`GeneratorExit` exceptions raised by the generator function are +caught internally and do not result in a call to ``sys.excepthook``. .. seealso::