Sunday 29 September 2013

Why doesn't java compiler show a warning for an obvious dividing by zero?

Why doesn't java compiler show a warning for an obvious dividing by zero?

This is just my curiosity to know why java compiler doesn't show any
warning in this case while it shows warning for unchecked operations to
predict a probable ClassCastException.
public class DivideByZero {
public static void main() {
int number = 3/0;
System.out.println(number);
}
}
Above code is guaranteed to produce an ArithmeticException.
This is an example only. There are more ways to guarantee a runtime
exception without any warning during compilation.

No comments:

Post a Comment