[jdom-interest] Re: NoSuch*Exception

Joseph Bowbeer jozart at csi.com
Tue Jun 27 22:01:14 PDT 2000

> With the current set of methods, exceptions actually
> seem to allow for simpler code.  Using exceptions also
> allows you to read an arbitrary number of attributes
> which are all required or implied by the DTD, with
> only one sanity-checking catch clause.  With a null
> return we'd all be too lazy to do n-many sanity checking
> null return checks, and in some cases that'll result in
> nasty NPEs.
> -jh-

I'm keeping my mouth shut on this issue, too, but that doesn't
prevent me from typing :)

I definitely favor returning null, ie, *not* throwing an

In a large number of situations, the absence of an attribute or
element is not an exceptional circumstance, and JDOM's accessor
methods are in no position to arbitrate.

In some situations the *presence* of a particular attribute or
element is exceptional.  In the many situations where an attribute
or element is optional, having the accessor throw an exception
complicates matters to the same degree that it simplifies things
in Jason's example above.

This reminds me a little of the "mechanism vs policy" debate that
influenced the design of the X Windows System.  The X designers
wanted to provide mechanism, not dictate policy.  In my opinion,
throwing a NoSuch*Exception is too close to making a policy

As I mentioned once, I think the analogy that someone pointed out
between JDOM's accessors and the 'get' method in HashMap is
instructive. (HashMap's accessor returns null if no such object

On the other hand, a NoSuch*Exception would seem more indicative
of a clear exception, such as trying to access past the end of a
List or Iterator.

--Joe Bowbeer

More information about the jdom-interest mailing list