Darren Roberts <robertsdjguard-poi <at> yahoo.com> writes:

> 
> Yes you can do that, I do it myself by in my SAX processors overidden 
DefaultHandler.startElement method,
> simply detect the row element, parse the attribute to get the row number 
(or 
increment an internal counter
> if you prefer) and then do a check to see whether you've reached or passed 
the row 
you wish to stop on. In my
> case at this point I throw a custom exception (SAXRowReachedException) 
which I 
explicitly handle in the
> calling code. 
> 
> I know that using exceptions for flow control is bad form, but I feel it 
is 
technically ok as by that point I
> should have found the required headers and if I've not then that's an 
exceptional 
event. Even IBM use the
> same method here:
> 
> http://www.ibm.com/developerworks/library/x-tipsaxstop/
> 
> Refer to their code if my description isn't clear.
> 


Thank you Darren for your suggestion, your description was very clear, 
quite easy to throw a custom runtime exception, and to catch it at the 
top of my processor.

I agree with you that exceptions is not the most elegant way to make flow 
control, but there's some times where is preferable, when the steps you want 
to exit are so many, or (like this case with SAX) when you use a third party 
framework with callbacks and you don't want to modify the code of the 
framework.

It works very well now, and the performance improvement is very clear!

Cheers


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to