Re: Strange java behaviour



priyom wrote:
Please got through the following code snippet.

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.


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.

Patricia
.



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)