| > So, the sad conclusion is: all problems must be resolved individually depending on a specific usage context. ...and that's a good thing. Recognising that specific usage contexts require specific recovery strategies is a key part of effective program design. Division by zero is an exception, yes. That's basic math. Getting to the point where one of your inputs is "bad" (zero in this case) shows that you have a problem. You should either catch zero up front with a conditional or catch it when it blows up, with an exception. Python favors the latter. But without context you don't know what that bad input means and so you cannot "fix" division by zero in the general case because it isn't the division by zero that is the cause of the problem. Asking "what should a division by zero actually return?" is the wrong question asked at the wrong point with the wrong information. Does the zero indicate lack of initialization? Does it indicate an empty container or volume? Does it indicate absence? How much of a problem to the logic of the program is this particular zero? How much of a problem is it for the person running it? So while I personally dislike exceptions and prefer return codes, exceptions are just the messenger here and they are an effective messenger. Don't shoot them. |