I have the following code:
public static void main(String[] args) {
try {
int d1 = 3;
int d2 = 0;
int d = d1/d2;
} catch (Exception ex) {
System.out.println("Exception");
}
}
When this code is run, it is obvious that exception will occur.
However, if I change the code as follows:
public static void main(String[] args) {
try {
double d1 = 3;
double d2 = 0;
double d = d1/d2;
} catch (Exception ex) {
System.out.println("Exception");
}
}
Then the exception does not throw. I really don’t get it.
Can anyone elaborate on that, please?
Because divide a double by 0.0 will produce NAN or +/- infinity, not an exception.