[jdom-interest] getChildTextNormalize()

Alex Rosen arosen at silverstream.com
Wed Oct 3 13:51:33 PDT 2001


Ugh.

We have conflicting requirements here:

- An API should be fail-safe
- An API should be pleasant to use
- Exceptions should be used for exceptional conditions

I think the first requirement indicates that we should throw an exception,
and the other two indicate that we should return null. (And I don't buy the
argument that one of these requirements trumps the other ones. There's no
point in having a fail-safe API if nobody uses it.)

The thing to remember here is that it may be perfectly valid for an element
to contain or not contain a child (that's why DTDs have the ? option). We
can't know ahead of time if this missing child is an exceptional condition
or not, so we shouldn't throw an exception. Furthermore, the API user may
know which children are present, if the XML document has already been
validated against a DTD. Forcing him to add a try/catch block will just
annoy him and make the API more unpleasant to use.

Please read the discussions from June/July 2000 (mostly starting with
"NoSuch*Exceptions" or "NoSuchChildException") before we reopen this
discussion.

Alex




More information about the jdom-interest mailing list