[jdom-interest] Re: NoSuch*Exception

Sirtaj Singh Kang ssk at physics.unimelb.EDU.AU
Wed Jun 28 04:31:58 PDT 2000


I personally prefer throwing an exception, because it reduces the chances
of bugs. Most programmers have the tendency of writing "best case" code
that assumes that nothing will go wrong and you can always write the error
handling code later. 

The result? The code checking for a missing element rarely gets written,
and your bug only shows up on the odd chance of a null exception.

The chance of an exception being thrown forces programmers to deal with
the situation up front. I'm sure a lot of you consider yourselves to be
above errors like these, but everyone makes mistakes, and you don't want
them showing themselves in the field. This is what exceptions were
designed for in the first place.

I'm also of the opinion that the bit of somewhat ugly code you have to
write to catch an exception when checking for an optional element is made
up by not having to check for null on every call.

My 2c...


PS. Validation of the document won't save you from misspelling the element
name in your code.

Sirtaj S. Kang       taj at kde.org         ssk at physics.unimelb.edu.au
Univ of Melbourne	The "gui" in "Penguin" is pronounced "K-D-E"

More information about the jdom-interest mailing list