[jdom-interest] NoSuch*Exceptions in JDOM

Elliotte Rusty Harold elharo at metalab.unc.edu
Fri Jun 16 06:31:27 PDT 2000

At 11:11 AM +0200 6/15/00, Simon Rade wrote:
>Element's methods getAttribute() and getChild() now throws
>NoSuchElementException and NoSuchAttributeException.
>Do you think this is better than returning null in such cases?
>Since it often happens that you don't know whether child or attribute
>exists and it is very awkward to handle those Exceptions.

As I was working on my presentation for XMLDevCon, I noticed that 
JDOM is inconsistent here. Some methods return null when no such item 
is found (Document.getDocType) and others throw an exception 
(Element.getAttribute, Element.getChild). A few others return empty 
strings or lists.

On Monday, and Friday, I believe the first batch are correct. On 
Tuesday, and Saturday I agree with the second. On Thursday and Friday 
I hold with the third. And on Sunday, I believe all three at once. 
But all days of the week I feel we should be consistent and pick one 
or the other.

| 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/     |

More information about the jdom-interest mailing list