I learnt in the past that Exception should be fired when there is somthing in the program which is not normal. For example an error when reading a file. If you look this python code you will see that a StopIteration Exception is fired. But this is not an anormal behaviour of the program. So my question is: Should we raise an exception in this case ? Thanks
class MyIterator():
def __init__(self, n):
self.max = n
def __iter__(self):
self.count = 0
return self
# For Python3
def __next__(self):
if self.count == self.max:
raise StopIteration
self.count += 1
return self.count - 1
c = MyIterator(4)
for i in c:
print(i)