On Sat, Apr 11, 2020 at 12:28 AM Greg Ewing
On 11/04/20 1:15 am, Chris Angelico wrote:
StopIteration wants to say hello :)
By "rare' I mean as a proportion of APIs in existence. StopIteration is frequently used, but it's just one API.
The only other one I can think of in the stdlib is EOFError, and that isn't even used all that much.
AttributeError, KeyError/IndexError, and GeneratorExit (and StopAsyncIteration) want to say hi too. They're all used as a signal for "there isn't anything I could return here so I have to not return". Even if that isn't an error state, it still has to be signalled with an exception. Unless there's to be a *third* way for a function to indicate something, namely a non-value-return, but then you have to figure out how you receive that, and how you would refactor a function that is capable of returning an object or returning a lack of object. And then this third mechanism would end up looking either like exception handling, or like the return of a "package" object, eg return (True, X) for the successful return and return (False, None) for the unsuccessful. ChrisA