1Z0-809 · Question #56
public class Test { public static void dispResult(int [] num) { try { System.out.println (num [1] / (num[1] - num[2])); } catch (ArithmeticException e) { System.err.println("first exception"); } }…
The correct answer is E. Third Exception. Option E is correct because arr has only two elements (indices 0 and 1), so accessing num[2] inside dispResult throws an ArrayIndexOutOfBoundsException - not an ArithmeticException - meaning the catch block in dispResult is skipped and the exception propagates back to main…
Question
Options
- A0
- BDone First Exception
- CDone Second Exception
- DDone Third Exception
- EThird Exception
How the community answered
(16 responses)- B13% (2)
- C6% (1)
- E81% (13)
Explanation
Option E is correct because arr has only two elements (indices 0 and 1), so accessing num[2] inside dispResult throws an ArrayIndexOutOfBoundsException - not an ArithmeticException - meaning the catch block in dispResult is skipped and the exception propagates back to main. There, it bypasses the IllegalArgumentException handler (wrong type) and is caught by the broader catch (Exception e) block, printing "third exception" with no other output before it.
Why the distractors fail:
- A (0): The array access crashes before any division can occur, so no value is ever printed.
- B & C & D: The word "Done" never appears in the code - there is no such
printlnstatement, so any choice containing it is immediately wrong. - C specifically:
ArrayIndexOutOfBoundsExceptionis not a subtype ofIllegalArgumentException, so that handler is never triggered.
Memory tip: Think of exception handlers as a type-filter chain - an exception only gets caught if its type matches or is a subtype of the declared catch type, and it bubbles up through every enclosing try block until something matches. Exception is the safety net at the bottom of the hierarchy.
Community Discussion
No community discussion yet for this question.