@too_many_usernames said:
@eclipsed4utoo said:
So lets say that you have an integer field that is part of a class. This integer field will be used as the denominator of a fractional computation. Of course, we don't want a 0 as the denominator. Using this "absolutely no point" programming style, you only need to do the check in ONE PLACE, which would be in the "set" part of the property. Do you have an easier/better way of doing this check EVERY TIME this value is set?
I almost always treat divide by zero errors as a design issue, not a runtime issue.
If you ever write code which does division, you have to make sure that a zero never has a chance to become a divisor. The problem is always in the thing which generated the zero, not in the setting of the value of the denominator to zero. Another rule of thumb is that you have to make sure your equations are valid in the first place (a good example is computing instantaneous miles per gallon while coasting with the engine off - using the MPH/GPH equation is invalid there because instantaneous miles per gallon is inherently undefined with zero fuel flow and the equation just doesn't apply at all - it should never be executed in that situation (and don't make me cry harder by replacing 0 with "an arbitrary and always incorrect small number" to prevent an exception please!) ).
even when the user is giving you the values for the computation?