[jdom-interest] [Vote] NoSuchChildException
Steve Odendahl
steve.odendahl at central.sun.com
Thu Jul 13 08:31:34 PDT 2000
On Thu, Jul 13, 2000 at 08:26:52AM -0400 or thereabouts, Elliotte Rusty Harold wrote:
> At 11:13 AM +0300 7/13/00, Petri Wessman wrote:
[snip]
>
> Maybe the real point of contention is that I think not getting
> something you ask for by name is an exceptional condition, similar to
> trying to open a file that turns out not to exist; whereas some other
> posters seem to feel that it's quite natural that something they ask
> for by name wouldn't be there. That view just seems strange and alien
> to me. As somebody else pointed out, if you really don't expect that
> the child will be there when you ask for it, then what's needed is a
> method to ask whether it exists.
I think comparing this situation with trying to open a non-existent file
isn't appropriate. Here we've already survived all the dangers (that is,
exceptional situations) of reading some XML (I/O, parsing), and now
there's an in-memory data structure we wish to query. Generally speaking,
in all the Java APIs I've encountered, checked exceptions are not thrown
when querying an in-memory data structure. (Can anyone come up with
a counter-example?)
I would compare it more with java.util.Properties. There, the load
method throws an exception if an error occurs during input, but the
getProperty method (asking for something by name!) returns null if
the property isn't there.
You can argue that this is poor design, but it's certainly idiomatic -
it pervades all the core APIs. (The primary reason, I'm sure, being
that a lot of these are built on Hashtable or HashMap, which returns
null if no mapping for a key is found.) Since it's idiomatic, an API
in a different style will be harder to understand.
Steve Odendahl
(Not speaking for Sun Microsystems, Inc.)
>
> +-----------------------+------------------------+-------------------+
> | 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/ |
> +----------------------------------+---------------------------------+
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com
More information about the jdom-interest
mailing list