[jdom-interest] [Vote] NoSuchChildException
randall at nls.net
Wed Jul 12 20:10:13 PDT 2000
On Wed, 12 Jul 2000 13:51:36 -0400, Elliotte Rusty Harold wrote:
>I get a very strong feeling of "We don't need no stinking exceptions"
>in this thread; and I don't think it's a rational response.
I have written a lot of Java code, have come to really like the exception facility of Java, and use it a great deal. Yet I oppose exception in this instance because an absence of an attribute or element is to
me, as a database designer type, the logical equivalent to a null in a particular row and column in a database.
Well, if I read a database field using JDBC and it is null then JDBC doesn't throw an exception because null is a legal value for that field. I think that was a wise choice on the part of the JDCB API
>they're a lot of programmers out there who don't like exceptions,
>never really understood them in the first place, and certainly don't
>feel comfortable with them now. I see this all the time in the
>students I teach, and one of the things I insist on in my classes is
>making sure my students use exceptions whether they want to or not.
>I think they're a lot of programmers who don't want to have to think
>about how to handle exceptions. Returning null lets them ignore the
>problem and pretend it's gone away. All claimed benchmarks aside,
>that's its biggest attraction.
No it isn't. There are programmers with good style (though I guess I can only look at my own style) who are against throwing an exception in this situation.
The real problem here is the very existence of optional attributes and optional elements. Its creating the same problems in XML that nullable columns create in RDBMSs. No matter how you handle them
its going to be kludgy.
>Throwing the exception is the right thing to do. It requires
>programmers to handle the case where the element isn't there.
Which is the logical equivalent of a null field in a database row. See my message I posted on Mon Jul 10 entitled:
"About optional values, nulls, and exceptions: its relational all over again"
>reason checked exceptions exist is precisely because programmers
>can't be relied on to check error codes and return values.
There is some value in the idea that requiring an exception would be a way to tell you that an attribute can be null (ie missing). But I don't find the argument sufficiently compelling. I read stuff out of
databases all the time and have to check for null results on nullable fields all the time. This is not causing problems in my experience.
>exactly what we're dealing with here. Whichever way the vote goes,
>this method will cause exceptions. The only question is whether these
>will be NoSuchChildExceptions that will be caught in a relevant catch
>block, or uncaught NullPointerExceptions that bring the whole program
More information about the jdom-interest