| ▲ | dotancohen 20 hours ago | |
Exceptions are for the exceptional cases - the ones that mean normal operations are being suspended and error messages are being generated. Don't use them for control flow. | ||
| ▲ | mort96 19 hours ago | parent | next [-] | |
In Python, an iterator raises a StopIteration exception to indicate to the for loop that the iterator is done iterating. In Python, the VM raises a KeyboardInterrupt exception when the user hits ctrl+c in order to unwind the stack, run cleanup code and eventually exit the program. Python is a quite heavy user of exceptions for control flow. | ||
| ▲ | Hendrikto 19 hours ago | parent | prev [-] | |
Typically yes, but not in Python. In Python it is quite common and accepted, and sometimes even recommended as Pythonic to use exceptions for control flow. See iterators, for example. I really dislike this too, but that’s how it is. | ||