When I ran this program multiple times, I got different output:
public class Demo {
public static void main(String[] args) {
try {
System.out.println("try block");
int a = 10 / 0;
} catch (Exception e) {
System.out.println("catch block");
int a = 10 / 0;
} finally {
System.out.println("finally block");
int a = 10 / 0;
}
}
}
First output:
Exception in thread "main" java.lang.ArithmeticException: / by zero
at kd.demo.Demo2.main(Demo2.java:14)
try block
catch block
finally block
Second output:
Exception in thread "main" try block
catch block
finally block
java.lang.ArithmeticException: / by zero
at kd.demo.Demo2.main(Demo2.java:14)
Third output:
Exception in thread "main" try block
catch block
finally block
java.lang.ArithmeticException: / by zero
at kd.demo.Demo2.main(Demo2.java:14)
When I compiled and executed this program multiple times, I got different output. Most of the time I got the third one which is not a problem. However, I am confused about other output (first and second).