
On Tue, Mar 01, 2022 at 11:50:42PM +0000, Rob Cliffe via Python-ideas wrote:
It doesn't feel right to me to use exceptions purely to direct control flow. YMMV.
Then Python is the wrong language for you, because it uses exceptions to direct control flow *wink* The iteration protocol uses StopIteration to end iteration. The older sequence protocol uses IndexError for the same purpose.
As I see it, the original meaning of an exception (in whatever language) is "something unexpected has happened" or "something has gone wrong".
No. An exception is *something EXCEPTIONAL has happened*. That could be something unexpected, or an error, but it can also be something boringly expected and normal, such as KeyError (key not found), or StopIteration (finite iterator has reached the end) etc. Really, pretty much every SpamError exception can be considered a non-error, depending on the semantics of how it is being used. duck.quack # AttributeError signals an error condition dog.quack # AttributeError signals the expected, non-error condition but this goes double for KeyError, where "missing key" is boringly normal. Using signals for flow control is an old, and fundamental, technique. Exceptions are just another kind of signal. https://ix.cs.uoregon.edu/~norris/cis330/slides/CIS330_Week9.pdf -- Steve