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.
Because technically a divide by zero is a valid program. Compilers only determine the validity of the program not whether there will be a runtime problem. It would be technically incorrect for a compiler to not let you compile a program with a divide by zero since it's valid.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With