What is the result?

Given:

01. static void test() throws Error {
02. if (true) throw new AssertionError();
03. System.out.print(“test “);
04. }
05. public static void main(String[] args) {
06. try { test(); }
07. catch (Exception ex) { System.out.print(“exception “); }
08. System.out.print(“end “);
09. }
10. }

What is the result?

Given:

01. static void test() throws Error {
02. if (true) throw new AssertionError();
03. System.out.print(“test “);
04. }
05. public static void main(String[] args) {
06. try { test(); }
07. catch (Exception ex) { System.out.print(“exception “); }
08. System.out.print(“end “);
09. }
10. }

What is the result?

A.
end

B.
Compilation fails.

C.
exception end

D.
exception test end

E.
A Throwable is thrown by main.

F.
An Exception is thrown by main.

Explanation:
Exception in thread “main” java.lang.AssertionError
at A.test(Main.java:2)
at A.main(Main.java:6)



Leave a Reply 1

Your email address will not be published. Required fields are marked *


fjbo221

fjbo221

To catch the AssertionError, the following is needed before (or after) the line 07.
catch (Error er) { System.out.print(“error “); }