+ 2

Why a double on division with 0.0 doesn't give an Arithmetic Exception. Rather shows Infinity?

Hii, While practicing and understanding java i got to know about the Arithmetic Exception "divide by 0". I tried throwing this exception myself by dividing a double var with a 0.0, however it showed infinite in both the cases (forcible throwing both runtime and compile time exception failed miserably). Can you please explain why did this happen? When does it give out the exception, when does it print "infinte". https://code.sololearn.com/c881zMZK76bw/?ref=app

6th Jan 2022, 1:27 PM
Ruchika Sehgal
Ruchika Sehgal - avatar
2 odpowiedzi
+ 3
6th Jan 2022, 2:01 PM
Lisa
Lisa - avatar
+ 1
That trick works in other languages, but not java. I think it is wrong for java to give a single valid result since the result of dividing by zero is mathematically ambiguous.
6th Jan 2022, 9:54 PM
Brian
Brian - avatar