[jdom-interest] [Vote] NoSuchChildException

Elliotte Rusty Harold elharo at metalab.unc.edu
Thu Jul 13 05:26:52 PDT 2000

At 11:13 AM +0300 7/13/00, Petri Wessman wrote:

>This is getting a bit thick. First of all, I'm an experienced,
>professional Java programmer (among other things), and I've both coded
>Java and read about it extensively. I also love exceptions, threads
>and other advanced features that Java provides. OTOH, it's possible to
>use exceptions in inappropriate ways, just as it is possible to use
>multihtreading in inappropriate ways.

Good. I suspect most subscribers on this mailing list are also 
experienced Java programmers and are familiar with how to do this, 
and will check for null at least 50% of the time, and probably catch 
the other 50% during debugging. But I also think that this is a very 
unusual and self-selected group. I am convinced that the majority of 
programmers writing Java code cannot be relied on to do this. And 
that the whole point of a simpler API is to make it as difficult as 
possible to do the wrong thing, and as easy as possible to do the 
right thing. That a solution isn't perfect doesn't mean it isn't 
better. That you can't do everything doesn't mean you can't do 

>Putting benchmark references in the form of "claimed benchmarks"
>implies that the results and/or the claimers or the results are
>suspect, which I find a bit insulting. There are numerous sources for
>the fact that throwing exceptions in Java is very expensinve compared
>to return values. These sources are supported by my quick benchmarks,
>such as they are. If you knew the design of the typical JVM, it should
>be obvious to you why exceptions are comparatively slow in Java.

I still stick to this point. I found the benchmarks posted to be 
thoroughly misleading and deceptive. They failed to take into account 
the fact that far more often than not no exception would be thrown. 
Exception handling in Java VMs is designed, quite rightly, to be zero 
cost in the case where no exception is thrown.

Maybe the real point of contention is that I think not getting 
something you ask for by name is an exceptional condition, similar to 
trying to open a file that turns out not to exist; whereas some other 
posters seem to feel that it's quite natural that something they ask 
for by name wouldn't be there. That view just seems strange and alien 
to me. As somebody else pointed out, if you really don't expect that 
the child will be there when you ask for it, then what's needed is a 
method to ask whether it exists.

| 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