(This is a follow up question to Why is this exception is not printed? Why is it showing an error?)
Here in the below code why is the ArithmeticException not triggered?
class Exp
{
public static void main(String args[])
{
float d,a=1;
try
{
d=0;
a=44/d; //no exception triggered here.. why?
System.out.print("It's not gonna print: a="+a);
}
catch(ArithmeticException e)
{
System.out.println("Print exception: "+e);
}
}
}
Instead the output is:
It's not gonna print: a=Infinity
What happens?
A division by zero throws an exception for integer values, but not for floating values. This is defined in the JLS #15.17.2:
If you change the type of
aanddtoint, you will get an exception.