0
What will be the output of the program?
public class ExceptionTest {
public static void main(String[] args) {
try {
System.out.println("Result: " + calculate(10, 0));
} catch (ArithmeticException e) {
System.out.println("ArithmeticException caught: " + e.getMessage());
} catch (Exception e) {
System.out.println("General exception caught: " + e.getMessage());
} finally {
System.out.println("In finally block.");
}
}
public static int calculate(int a, int b) throws Exception {
try {
return a / b;
} catch (ArithmeticException e) {
throw new Exception("Division by zero not allowed");
} finally {
System.out.println("Inner finally block executed.");
}
}
}- AInner finally block executed. General exception caught: / by zero In finally block.
- BInner finally block executed. General exception caught: Division by zero not allowed In finally block.
- CInner finally block executed. Result: 0 In finally block.
- DInner finally block executed. ArithmeticException caught: / by zero In finally block.
Correct answer: B