This code : try { double a = 10/0; } catch(ArithmeticException e) { System.out.println("catch"); } print catch but this code:
javi cervera
Greenhorn
Joined: Jan 17, 2002
Posts: 16
posted
0
this code: try { double a = 10.0/0.0; } catch(ArithmeticException e) { System.out.println("catch"); } no print catch can anybody explain me please ? thanks in advanced
Ron Newman
Ranch Hand
Joined: Jun 06, 2002
Posts: 1056
posted
0
Floating-point division by 0 doesn't cause an ArithmeticException. It produces an Infinity constant (or a NaN, if you divide 0 by 0).
Ron Newman - SCJP 1.2 (100%, 7 August 2002)
Thomas Paul
mister krabs
Ranch Hand
Joined: May 05, 2000
Posts: 13974
posted
0
And just to make it clear: float f = 10/0; //is integer math even though the result is being moved to a float. For example: float f = 10/20; //f equals 0.0 because 10/20 = 0 in integer math
wasarta, Welcome to Javaranch We'd like you to read the Javaranch Naming Policy and change your publicly displayed name (change it here) to comply with our unique rule. Thank you.