Built-in Exceptions

GeneratorExit — exception class

A generator receives this signal when close() requests termination at a suspension point. Cleanup may run; a generator must not yield a new value in response. It is not an ordinary application error and does not inherit Exception. The example raises a controlled stand-in to demonstrate handling; it does not cause the real system failure.

Formal Syntax & Structure

python syntaxpython
GeneratorExit

Return Value

type

The class object GeneratorExit; this reference documents the class identity, not a universal constructor signature.

Working Example

Example Snippetpython
try:    raise GeneratorExit()except GeneratorExit as error:    print(type(error).__name__)
Python Reference