[jdom-interest] NoSuch*Exceptions in JDOM

Alex Chaffee guru at edamame.stinky.com
Sun Jul 9 12:31:46 PDT 2000


On Fri, Jul 07, 2000 at 02:48:50PM +0200, Andre Van Delft wrote:
> In some cases I want a NoSuch*Exception, when a child or attribute must
> be present.
> In some cases the child or attribute is optional; then I want null
> returned since there is no exceptional situation, and my code should be
> simple.
> 
> We can have it both ways.
> I use a util function getChild that returns a null if the child is
> absent.
> I prefer the Element.getChild function to behave like this.
> The old Element.getChild functions throwing the exceptions may well be
> renamed into mustGetChild.
> That would do, IMHO.

I'm with you.  I like the terminology "mustX", but that breaks the
JavaBean convention of starting accesors with "get".  But I think null
should be returned by the standard methods; Cornell&Horstmann (and
others) taught me not to overuse exceptions where a compare will do.

If "null" is a valid value for object references, meaning "the object
that does not exist", then having getChild() return null is perfectly
within the bounds of type semantics.  And it is, so it is.

Unfortunately, Messrs. McLaughlin and Hunter seem to prefer a frenzy of
exceptions.

Maybe it's time for a straw poll?  Reply "null" or "throw"...

 - Alex


-- 
Alex Chaffee                       mailto:alex at jguru.com
jGuru - Java News and FAQs         http://www.jguru.com/alex/
Creator of Gamelan                 http://www.gamelan.com/
Founder of Purple Technology       http://www.purpletech.com/
Curator of Stinky Art Collective   http://www.stinky.com/



More information about the jdom-interest mailing list