Why is it that division by 0 in most programming languages causes the program to crash or to stop working?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

Why is it that division by 0 in most programming languages causes the program to crash or to stop working??

7th Dec 2017, 10:46 AM
Perez
Perez - avatar
3 Answers
7th Dec 2017, 10:56 AM
jay
jay - avatar
+ 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.
7th Dec 2017, 5:30 PM
Kirk Schafer
Kirk Schafer - avatar
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
14th Dec 2017, 5:55 AM
Lil Taco
Lil Taco - avatar