• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Whizlabs Exception Handling Question

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the confirmation!
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thats a relief!!
Thanks Joyce!
reply
    Bookmark Topic Watch Topic
  • New Topic