Built-in Exceptions

StopIteration — exception class

Signals exhaustion of a synchronous iterator. next(iterator, default) converts exhaustion into a fallback. Generator return values appear as StopIteration.value; an uncaught explicit StopIteration inside a generator becomes RuntimeError.

Formal Syntax & Structure

python syntaxpython
StopIteration

Return Value

type

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

Working Example

Example Snippetpython
try:    next(iter([]))except StopIteration as error:    print(type(error).__name__)
Python Reference