aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes ArithmeticException in doubles Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "ArithmeticException in doubles" Watch "ArithmeticException in doubles" New topic
Author

ArithmeticException in doubles

javi cervera
Greenhorn

Joined: Jan 17, 2002
Posts: 16
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
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
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
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


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Rahul Phadnis
Greenhorn

Joined: Aug 13, 2002
Posts: 7
Try this to make it absolutely clear
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
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.


SCJP Tipline, etc.
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
Since "10/0" is an integer division that produces a compile-time constant, why doesn't the compiler complain?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ArithmeticException in doubles