[jdom-interest] [Vote] NoSuchChildException

Brett McLaughlin brett.mclaughlin at lutris.com
Wed Jul 12 14:37:02 PDT 2000


Elliotte Rusty Harold wrote:
> 
> -1 on returning null
> 
> You asked for a reason for a -1 vote so I'll give you mine. I was
> initially undecided, but when I actually looked at the code people
> were proposing for returning null it struck me as completely the
> wrong way to do anything.
> 
> I get a very strong feeling of "We don't need no stinking exceptions"
> in this thread; and I don't think it's a rational response. I think
> they're a lot of programmers out there who don't like exceptions,
> never really understood them in the first place, and certainly don't
> feel comfortable with them now. I see this all the time in the
> students I teach, and one of the things I insist on in my classes is
> making sure my students use exceptions whether they want to or not.
> 
> I think they're a lot of programmers who don't want to have to think
> about how to handle exceptions. Returning null lets them ignore the
> problem and pretend it's gone away. All claimed benchmarks aside,
> that's its biggest attraction.
> 
> Throwing the exception is the right thing to do. It requires
> programmers to handle the case where the element isn't there. The
> reason checked exceptions exist is precisely because programmers
> can't be relied on to check error codes and return values. That's
> exactly what we're dealing with here. Whichever way the vote goes,
> this method will cause exceptions. The only question is whether these
> will be NoSuchChildExceptions that will be caught in a relevant catch
> block, or uncaught NullPointerExceptions that bring the whole program
> down.

Excellent reasoning! So since we all know people are going to be enraged
by this ;-), do you also feel we should not provide:

public Element getChild(String name, Element defaultValue);

?

-Brett

> 
> +-----------------------+------------------------+-------------------+
> | Elliotte Rusty Harold | elharo at metalab.unc.edu | Writer/Programmer |
> +-----------------------+------------------------+-------------------+
> |                  The XML Bible (IDG Books, 1999)                   |
> |              http://metalab.unc.edu/xml/books/bible/               |
> |   http://www.amazon.com/exec/obidos/ISBN=0764532367/cafeaulaitA/   |
> +----------------------------------+---------------------------------+
> |  Read Cafe au Lait for Java News:  http://metalab.unc.edu/javafaq/ |
> |  Read Cafe con Leche for XML News: http://metalab.unc.edu/xml/     |
> +----------------------------------+---------------------------------+

-- 
Brett McLaughlin, Enhydra Strategist
Lutris Technologies, Inc. 
1200 Pacific Avenue, Suite 300 
Santa Cruz, CA 95060 USA 
http://www.lutris.com
http://www.enhydra.org



More information about the jdom-interest mailing list