You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In section 7 of "What's New in Python 2.5" the
subsection on the close() generator method states:
close() raises a new GeneratorExit exception
inside the generator to terminate the iteration.
On receiving this exception, the generator's code
must either raise GeneratorExit or StopIteration;
catching the exception and doing anything else is
illegal and will trigger a RuntimeError.
This suggests that if a generator raises a new exception that is neither a GeneratorExit nor
StopIteration a RuntimeError is raised. But this
is not the case according to Part 4 of PEP-342's
"Specification Summary":
If the generator raises any other exception,
it is propagated to the caller.
The Python 2.5 interpreter is consistent with PEP-342:
Python 2.5 (r25:51908, Sep 19 2006, 09:52:17)
[MSC v.1310 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for
more information.
>>> defraise_wrong_exception():
... try:
... yield1
... yield2
... exceptGeneratorExit:
... raiseTypeError("Where is the RuntimeError?")
...
>>> i=raise_wrong_exception()
>>> i.next()
1
>>> i.close()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 6, in raise_wrong_exception
TypeError: Where is the RuntimeError?
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: