How do you eliminate exceptions from the premature termination of a Python generator / iterator?
For example, consider the following:
#!/usr/bin/env python def MyIter(): yield 1 yield 2 yield 3 raise Exception, 'blarg!' yield 4
I would expect an output:
value: 1 value: 2 value: 3 An error occurred: blarg! value: 4
However, after the exception, the iterator completes, and the value 4 never fails, although I handled the exception and did not break my loop. Why does he behave this way?
Cerin source share