by dijksterhuis · 7y ago · 0 comments
“except StopIteration” only watches for the specific StopIteration exception coming from the next() call on the Iterator (the bit included in the try block).
If there was then an, for example, “except Error” line afterwards, then anything that causes an Error exception (ValueError, TypeError etc) would call those lines.
If you get any exception that has not been explicitly referenced in an except clause, then the program will halt, with that exception as the error output.
Is this the case with python too? or throwing exception is "free" here?
It could even be more efficient than return value checking in certain cases.