This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Dealing with RuntimeException in SCJD Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Dealing with RuntimeException in SCJD" Watch "Dealing with RuntimeException in SCJD" New topic
Author

Dealing with RuntimeException in SCJD

Johnny Hunter
Ranch Hand

Joined: Jul 15, 2004
Posts: 37
Hi,

Is this necessary for this test to implement all the RuntimeExceptions that the JVM can throw in any weird case scenario, like InterruptedException, OutOfMemoryException and similar not so obvious ones? Thanks for your help in advance.


Johnny Hunter
SCJP 1.4
Philippe Maquet
Bartender

Joined: Jun 02, 2003
Posts: 1872
Hi Johnny,

What do you mean by "implement"?

Regards,

Phil.
Johnny Hunter
Ranch Hand

Joined: Jul 15, 2004
Posts: 37
implement == take care of it. Should I bracket my code around try/catch for OutOfMemory exceptions. Should I always wrap my wait around a while that retest the condition of the wait? Should I put some System.exit(number) in the catch of RuntimeExceptions or do some logging output or what? Thanks!
Robert Konigsberg
Ranch Hand

Joined: Jun 23, 2004
Posts: 172
What would you do if this wasn't SCJD, but a professional job assignment? Say, a contract?


SCJP 1.4 (91%)<br />SCJD 1.4 (376/400, 94%)
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11490
    
  95

Hi Johnny,

Originally posted by Johnny Hunter:
implement == take care of it. Should I bracket my code around try/catch for OutOfMemory exceptions. Should I always wrap my wait around a while that retest the condition of the wait? Should I put some System.exit(number) in the catch of RuntimeExceptions or do some logging output or what? Thanks!


What would you do if you did try to catch these exceptions? Kathy Sierra & Bert Bates had a comment in one of their books along the lines of "what would you put in the catch block of an OutOfMemoryException? Run the garbage collector? I am sure the JVM would say 'gee thanks, I never thought of that' ".

Most of the RuntimeExceptions are there to tell you that the JVM is in an invalid state and cannot continue processing. Trying to catch them and do some sort of processing goes against the whole concept.

However there are some RuntimeExceptions that you might want to catch though - those thrown when a number can't be parsed for instance, or where you have subclassed your own RuntimeException. But these will be specific exceptions that you know that you can catch and handle.

Regards, Andrew


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Dealing with RuntimeException in SCJD