Return to site

JAVA CERTIFICATION QUESTION: Rules about throwing checked exceptions in Java

· java

This quiz focuses on throwing checked exceptions.

Given the following class:

public class ArgsChecker {  
  public static void main(String[] args) {
    try {
      if (args.length == 0) {
        throw new IllegalArgumentException();
      }
    } catch (NullPointerException e) {
      System.out.print("NPE ");
      throw e;
    } catch (IllegalArgumentException e) {
      System.out.print("IAE ");
      throw e;
    } catch (Throwable t) {
      System.out.print("T ");
      throw t; // line n1
    } finally {
      System.out.print("F ");
    }
  }
}

Run with no arguments; choose one.:

A. The class compiles, runs, and prints NPE T F followed by a stack trace.

B. The class compiles, runs, and prints IAE T F followed by a stack trace.

C. The class compiles, runs, and prints IAE F followed by a stack trace.

D. The class does not compile. If you remove line n1, it compiles, runs, and prints NPE T F followed by a stack trace.

E. The class does not compile. If you remove line n1, it compiles, runs, and prints IAE T F followed by a stack trace.

F. The class does not compile. If you remove line n1, it compiles, runs, and prints IAE F followed by a stack trace.

 

·ꓛ sᴉ ɹǝʍsuɐ ʇɔǝɹɹoɔ ǝɥꓕ