This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Whizlabs Exception Handling Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Whizlabs Exception Handling Question" Watch "Whizlabs Exception Handling Question" New topic
Author

Whizlabs Exception Handling Question

J Sato
Ranch Hand

Joined: Mar 30, 2006
Posts: 40
I have a concern regarding the following from the Whizlabs quiz:

Consider that you have separate catch clauses for handling Throwable, Exception, and RuntimeException. Which catch clause has to appear first for the code to compile correctly?

A catch(Exception e){}
B catch(Throwable t){}
C catch(RuntimeException re){}

I chose A but Whizlabs said C was the correct answer. I confirmed C is correct with the following code:



I understand why C is correct because RuntimeException is narrower than Exception but from reading the K & B book (page 361) I understood that RuntimeExceptions are unchecked (like errors) so it did not matter if they were handled or declared.

Just for my own clarification, if Errors or RuntimeExceptions are caught, they must also adhere to the "narrowest first" rule, right? If this is in the book and I missed it, I'd greatly appreciate it if someone could let me know where it's discussed.

Thanks.
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
In general you do not have to deal with unchecked exceptions. However if you do have a catch block for an unchecked exception, it has to follow the same rules that apply to any catch block.
J Sato
Ranch Hand

Joined: Mar 30, 2006
Posts: 40
Thanks for the confirmation!
debolina chakravarty
Greenhorn

Joined: Apr 05, 2006
Posts: 5
Hi All!

While going through some of the posts of people who have passed the SCJP 1.4 exam, I found that some of them have got questions from files and Swing. Can you please advice me what I should study? I am taking the exam in 2 days so if you could tell me what all is relevant to the exam(as these are not there in the exam objectives), I would be very grateful.

Thanks.
Joyce Lee
Ranch Hand

Joined: Jul 11, 2003
Posts: 1392
Hi Debolina,

While going through some of the posts of people who have passed the SCJP 1.4 exam, I found that some of them have got questions from files and Swing. Can you please advice me what I should study?

File and Swing topics are not in the SCJP 1.4 exam. Also, have a look at this at SCJP FAQ.

Joyce
debolina chakravarty
Greenhorn

Joined: Apr 05, 2006
Posts: 5
Thats a relief!!
Thanks Joyce!
 
GeeCON Prague 2014
 
subject: Whizlabs Exception Handling Question