Kudos To Ian S

7 AM May 1, 2003
"Ian S" made this comment to Charles' post The Fishbowl: Swallowing Exceptions: Don't Do It!, and it deserves a replay right up the front of a blog somewhere.
I generally subclass RuntimeException for library code etc. There is one place where I swallow an exception:
int maxValues = Integer.MAX_VALUE;

try {
    maxValues = Integer.parseInt( 
            xmlElement.getAttribute("max") );
} catch( NumberFormatException nfe ) {
    //keep default.
Technically I should throw an IllegalArgumentException(nfe) or check for "", null, etc.

Anyway. This is what I paste in and commit to CVS whenever I catch (pun intended) a fellow coder swallowing exceptions. It rarely happens un-explicated now.


/* Will no-one*/ } catch( Exception e /* ! */ ) {
    //No getMessage() shall we ever see,
    //No System.exit( THIS_SHOULD_NOT_BE );
    //No RuntimeException( WONT_CATCH_ME );
    //No closure for Exception e,
    //for our programmer, with little thought,
    //has left Exception e uncaught!
}//Oh cruel bracket, how you limit the scope of his instance!

Posted by: Ian S on April 30, 2003 11:00 PM

So, does 'S' in Ian S stand for Suess?
By alang | # | Comments (0)
(Posted to Software Development)


Add Comment

(Not displayed)

(Leave blank line between paragraphs. URLs converted to links. HTML stripped. Indented source code will be formatted with <pre> tags.)

© 2003-2006 Alan Green