lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tatu Saloranta <>
Subject Re: query matching all documents
Date Fri, 23 May 2003 04:41:28 GMT
On Thursday 22 May 2003 07:32, Brisbart Franck wrote:
> You don't really need to take care of the deleted docs. When you'll try
> to get a deleted doc (reader.document(i) on a deleted doc), a
> IllegalArgumentException will thrown with the message 'attempt to access
> a deleted document'. Just catch this exception.

Although technically speaking that would work, in general it's almost always 
better to check for a condition that can occur  instead of waiting for an 
exception to occur. For example, if there is a chance that a reference may 
well be null, it's better to check for null than to do try-catch for 
NullPointerException; if no null is expected, no specific catch block is 
needed (it may make sense to have catch-all construct for robustness, but not 
for specific one).

Exceptions are to be used only for exceptional things, and for iterating over 
non-optimized index, finding a deleted doc is nothing too exceptional? If 
index is assumed to be optimal, and no deleted docs should be there, then it 
may be reasonable to use try-catch "just in case".

There's a significant overhead for just creating the exception object (JVM 
needs to unwind the whole call stack, and that's seldom optimized by VMs... 
because they optimize non-exception cases etc. etc.), and when iterating over 
all docs, this overhead may make traversing significantly slower if there are 
multiple deleted docs.

-+ Tatu +-

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message