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.
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.