If
b
is zero, then trying to do this:
ats = a / b;
will give you an exception because division by zero does not give you a "real world" number you can store in a
double
Very definately, 0 is not the correct result!
So there are two ways to handle it:
1) Check before you divide! Put a quick test in before you try, and report a problem if it won't work instead of doing it.
2) Use a
try...catch
block to detect errors and handle them gracefully:
try-catch (C# Reference) | Microsoft Docs[
^]