aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes SCJP 6 (kathy Sierra) Chap 5#3 Question Doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "SCJP 6 (kathy Sierra) Chap 5#3 Question Doubt" Watch "SCJP 6 (kathy Sierra) Chap 5#3 Question Doubt" New topic
Author

SCJP 6 (kathy Sierra) Chap 5#3 Question Doubt

Vicente de Rivera Iii
Greenhorn

Joined: Apr 23, 2009
Posts: 9
From SCJP 6 study guide (kathy Sierra) cert book,

Chap 5#3

Given:

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

Which could be used to create an appropriate catch block? (Choose all that apply.)
A. ClassCastException
B. IllegalStateException
C. NumberFormatException
D. IllegalArgumentException

The book's answer is C & D w/c I see is a legal catch.

My answer was C, I thought catching the most specific is appropriate. Am I wrong?

Thanks in advance! First time post here, I'll be taking the exam SCJP6 Next week
Greg Charles
Bartender

Joined: Oct 01, 2001
Posts: 2542
    
  10

Yes, NumberFormatException is the exception that would be thrown, but IllegalArgumentException is its superclass, so catching that would also do the job. The word "appropriate" is somewhat subjective, but I'd argue both are appropriate here, though I might waffle a bit if catching Throwable would also be. From what I remember about SCJP though, it's not trying to trick you with fine points about programing style.

Note: it's Kathy Sierra. Kathy Bates is the one who bashed in James Caan's knees in Misery
Vicente de Rivera Iii
Greenhorn

Joined: Apr 23, 2009
Posts: 9
Thanks a lot!
corrected Bates to Sierra

Greg Charles wrote:Yes, NumberFormatException is the exception that would be thrown, but IllegalArgumentException is its superclass, so catching that would also do the job. The word "appropriate" is somewhat subjective, but I'd argue both are appropriate here, though I might waffle a bit if catching Throwable would also be. From what I remember about SCJP though, it's not trying to trick you with fine points about programing style.

Note: it's Kathy Sierra. Kathy Bates is the one who bashed in James Caan's knees in Misery
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SCJP 6 (kathy Sierra) Chap 5#3 Question Doubt
 
Similar Threads
Bug in LearnKey SCJP 5 exams
Sierra's SCJP book SELF TEST
nit w/ chap.6 q.13 S&B
Passed SCJP 5.0 with 97%
SCJP