[jdom-interest] Re: NoSuch*Exception
Patrick.Dowler at nrc.ca
Wed Jun 28 09:54:29 PDT 2000
On Wed, 28 Jun 2000, Dino Valente wrote:
> I think you missed what people have been saying. Returning null should be
> used in cases where optional elements are accessed. It appears people are
> saying that is more convenient to check for null that using exception
> handling (i.e run-time errors would not occur in these cases; OK you have
> to make sure that you check for null). It is obvious to me we require both.
I've argued for returning null so far, but it is true that this does not remove
all exception throwing. For example, getAttribute("foo").getIntValue() can still
throw a NumberFormatException - and it should since that is an error!
Sadly (for me and the null-return bellied snitches) the attribute exmaple
is a good one of how exception throwing is easier than null-returning
since you always want the value... it is basically like those leaf-node
elements, where you just want the content: getChild("foo").getContent()
which is a nice thing to be able to write. You can catch NPE and assume
getChild returned null, but you have to check the trace to see for sure.
> It is curious to me that people readily accept that addChild from Element
> returns `this' for convienience but adding a routine that returns null for
> accessing elements seems to encounter a lot of resistance.
I guess it is because it is easy to discard a return value, so actually making
the return type void would not make it any easier for anyone :-) The other
laternative would be to do something a la swing and return the added
child, but that gets confusing fast...
Canadian Astronomy Data Centre
More information about the jdom-interest