Re: Strange java behaviour



priyom wrote:
class NanTest {

public static void main ( String args [ ] ) {
int intX = 10 ; // line 1
float floatX = 10 ; // line 2
double doubleX = floatX / 0 ; // line 3
double doubleY = intX / 0 ; // line 4
System . out . println ( doubleX == doubleY ) ; // line 5
}
}

It throws exception on line 4 but not on line 3.
Could anyone please explain this.

Patricia Shanahan wrote:
Line 4 is an int division by zero, and there is no way to represent the
result as an int, so it throws an exception.

Line 3 is a float division by zero, and there is a value,
Float.POSITIVE_INFINITY, that represents the result of dividing a
positive float by a zero float.

http://docs-pdf.sun.com/800-7895/800-7895.pdf
and
http://docs.sun.com/source/806-3568/ncg_goldberg.html

The latter is the HTML form of the former.

- Lew
.



Relevant Pages

  • Re: generics - constraint
    ... checks typeofand throws an exception if it isn't int, float, or ... Generics are very limited then because you cannot perform any ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Strange java behaviour
    ... It throws exception on line 4 but not on line 3. ... result as an int, ... Line 3 is a float division by zero, and there is a value, ... positive float by a zero float. ...
    (comp.lang.java.programmer)
  • Re: generics - constraint
    ... checks typeofand throws an exception if it isn't int, float, or ... Generics are very limited then because you cannot perform any ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Implementing exceptions of C++ in C
    ... When it gets to foo1(), foo1throws an exception of type int. ... it goes immediately to the handler. ...
    (comp.lang.c)
  • Re: Implementing exceptions of C++ in C
    ... When it gets to foo1(), foo1throws an exception of type int. ... it goes immediately to the handler. ...
    (comp.lang.cpp)