Catch StopIteration exception