[jdom-interest] Re: NoSuch*Exception
Dino Valente
dino at 3dstockcharts.com
Wed Jun 28 12:57:16 PDT 2000
At 11:05 AM 6/28/00 -0700, you wrote:
>Sirtaj Singh Kang wrote:
>>
>> On Wed, Jun 28, 2000 at 07:54:55AM -0400, Thomas M. Sasala wrote:
>> > Sirtaj Singh Kang wrote:
>> >
>> > If null is returned and it is not checked for,
>> > then you will get a null pointer exception. There's your
>> > error ;)
>>
>> Not until it is dereferenced. Consider that it might be put into
>> a database field or a collection. Then the effect of the error is
>> discovered two or three steps away from where it is actually located,
>> which is great if you enjoy debugging.
>>
>> (Please don't forget that this is probably by far the most common source
>> of runtime errors in programming languages that don't have exceptions.)
>
>In fact right now I'm trying to track down an NPE that a customer of one
>of my products is getting. It's especially bad because NPE's don't tell
>you what variable was null, the stack traces don't always include line
>numbers, and so I have to hand hold the customer.
>
>I think Sirtaj is making excellent points. I also saw someone post
>about the convenience of getChild("foo").getContent() -- something
>that's really only possible if we throw exceptions. Saying you'll catch
>an NPE here isn't compelling.
>
>-jh-
This is a good example in which exceptions is useful IF you are expecting
the child to be there. However, if the child is optional then the
programmer should be able to retrieve the child, check it to see if it is
null and then call getContent(). I'm not arguing to remove the exception
functionality in getChild. I'm arguing that we should provide another
routine that allows the programmer to check for null children.
Once again, it would be nice to allow the ability to define our own
Element/Document/Attribute classes when building the jdom document since
not everyone agrees what should be done here. Then each developer can
implement there own routines in these classes (I want to add more routines
in addition to the above routine).
dino
More information about the jdom-interest
mailing list