Hi,
I have a generator
I thought that the for would catch the StopIteration exception. myRange is an iterator as well as being a generator and the for would catch the StopIteration exception. Can't generators raise exceptions?
I have a generator
def myRange(start, end): while start < end: yield start start += 1 raise StopIteration for n in myRange(2, 5): print(n)I get a runtime error generator raised StopIteration. If I remove the raising of the StopIteration it works fine.
I thought that the for would catch the StopIteration exception. myRange is an iterator as well as being a generator and the for would catch the StopIteration exception. Can't generators raise exceptions?