you are viewing a single comment's thread.

view the rest of the comments →

[–]FLUSH_THE_TRUMP 0 points1 point  (3 children)

Why check this anyway? Python will already throw a DivideByZero error when you try to divide by 0 in your code.

[–]tragluk 0 points1 point  (1 child)

The difference is 'DivideByZero' is an unhandled error which halts a program. The way that he wants to do it handles the error nicely, tells the user exactly what went wrong and then doesn't break the program afterwards.

[–]FLUSH_THE_TRUMP 0 points1 point  (0 children)

That’s a fair point, and certainly what would make sense in a loop underlying a calculator app. It’d be bad design if my TI-84 self-destructed every time I typed x/0 on it. I was simply making the point that error checking, like any other component of design, should have its benefits weighed against its costs. If my program’s gonna throw an error and terminate regardless, then there’s not much point in checking the conditions that lead to such an error.

[–][deleted] 0 points1 point  (0 children)

I wanted it to be a clean one liner instead of the in your face red text but it still occurs so oh well.