Sunday, August 8, 2010

Exceptions

Courtesy of SCJP Sun® Certified Programmer for Java™ 6 Study Guide Exam (310-065) (9780071591065)
Chapter 5, Question 3

Given: try { int x = Integer.parseInt("two"); }

Which could be used to create an appropriate catch block? (Choose all that apply.) 

A. ClassCastException

Not in NumberFormatException’s class hierarchy.

B. IllegalStateException

Not in NumberFormatException’s class hierarchy.

C. NumberFormatException

Correct. Integer.parseInt can throw a NumberFormatException.

D. IllegalArgumentException

Correct. Integer.parseInt can throw a NumberFormatException, and IllegalArgumentException is its superclass (i.e., a broader exception).

E. ExceptionInInitializerError

Not in NumberFormatException’s class hierarchy.

F. ArrayIndexOutOfBoundsException
  
Not in NumberFormatException’s class hierarchy.

No comments:

Post a Comment