+ 5
Why is it that division by 0 in most programming languages causes the program to crash or to stop working??
3 Respostas
+ 3
It throws an exception because the operation results are undefined (believe it or not /0 is actually allowed; program-killing exceptions are like a default feature), which leaks into your running program like 'undefined' or 'NaN' messes up entire Javascript calculations, even some distance from the problem.
0
Division by zero does not exist mathematically.
You could use a code like this:
if (divider == 0) {
//other code here
} else {
//division code goes here
}
or use a try/except or try/catch