public class Test {
public static int temp(String a, String b) {
try {
System.out.print("A");
return Integer.parseInt(a)/Integer.parseInt(b);
} catch(ArithmeticException e) {
System.out.print("C");
return 0;
} finally {
System.out.print("D");
return -1;
}
}
public static void main(String[] args) {
try {
System.out.print(temp("1", null));
} catch (Exception e) {
System.out.print("E");
} finally {
System.out.print("F");
}
}
}
The output for this program is AD-1F.
But since b is null, Integer.parseInt(b) should throw a NumberFormatException, which is propagated back, and should be caught by the catch block in the main method. The output that I traced would be AD-1EF.
If the code in main method try-block is replaced with Integer.parseInt(null), output will be EF, which means that the NumberFormatException thrown by Integer.parseInt(null) should be caught in the first case.