Python Programming - Generators - Discussion

Discussion Forum : Generators - General Questions (Q.No. 80)
80.
How does the generator.close() method differ from generator.throw(GeneratorExit)?
They are equivalent in functionality
generator.close() raises a GeneratorExit exception, while generator.throw(GeneratorExit) terminates the generator
generator.throw(GeneratorExit) raises a GeneratorExit exception, while generator.close() terminates the generator
generator.throw(GeneratorExit) and generator.close() are not valid methods
Answer: Option
Explanation:
generator.close() raises a GeneratorExit exception to signal that the generator should be closed. generator.throw(GeneratorExit) is not a common approach for closing generators.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.