Python Programming - Generators - Discussion

Discussion Forum : Generators - General Questions (Q.No. 71)
71.
How does the generator.throw() method differ from the generator.close() method?
They are equivalent in functionality
generator.throw() raises a specific exception in the generator, while generator.close() terminates the generator
generator.close() raises a StopIteration exception, while generator.throw() terminates the generator
generator.throw() raises a StopIteration exception, while generator.close() terminates the generator
Answer: Option
Explanation:
generator.throw() raises a specific exception in the generator, while generator.close() terminates the generator by raising a GeneratorExit exception.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.