Python Programming - Generators - Discussion

Discussion Forum : Generators - General Questions (Q.No. 42)
42.
How does the generator.throw(ValueError, "message") method differ from raise ValueError("message") when used with a generator?
They have the same effect on the generator
generator.throw(ValueError, "message") is used to raise an exception inside the generator, while raise ValueError("message") is used outside the generator
raise ValueError("message") is used to raise an exception inside the generator, while generator.throw(ValueError, "message") is used outside the generator
generator.throw(ValueError, "message") stops the generator, while raise ValueError("message") continues the generator's execution
Answer: Option
Explanation:
generator.throw(ValueError, "message") is used to raise an exception inside the generator, while raise ValueError("message") is used outside the generator to raise an exception.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.