You don't need to raise that
In your code it handles the StopIteration when generator is exhausted, but then you raise the exception that is not handled
StopIteration
.def myRange(start, end): while start < end: yield start start += 1 for n in myRange(2, 5): print(n) spam = myRange(2, 5) while True: print(next(spam))
Output:2
3
4
2
3
4
Traceback (most recent call last):
File "***", line 11, in <module>
print(next(spam))
StopIteration
as you can see, it will raise it when needed.In your code it handles the StopIteration when generator is exhausted, but then you raise the exception that is not handled
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs