Multiple choice technology

Given: 11. static void test() throws Error { 12. if (true) throw new AssertionError(); 13. System.out.print("test "); 14. } 15. public static void main(String[] args) { 16. try { test(); } 17. catch (Exception ex) { System.out.print("exception "); } 18. System.out.print("end "); 19. } What is the result?

  1. end

  2. compilation fails

  3. exception end

  4. exception test end

  5. A Throwable is thrown by main.

  6. An Exception is thrown by main.

Reveal answer Fill a bubble to check yourself
E Correct answer
Explanation

The test method throws an AssertionError, which is a subclass of Throwable and Error, but not Exception. The catch block catches Exception, so the AssertionError bypasses it and propagates out of main, resulting in an uncaught Throwable thrown by main.