Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dealing with RuntimeException in SCJD

 
Johnny Hunter
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Philippe Maquet
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Johnny,

What do you mean by "implement"?

Regards,

Phil.
 
Johnny Hunter
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What would you do if this wasn't SCJD, but a professional job assignment? Say, a contract?
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 11854
185
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic