[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: SAXException, checked, buy why?
* Karl Waclawek <karl@w...> [2005-01-05 09:29]: > Alan Gutierrez wrote: > > >>But again, if the Error class is abstract, one can subclass with > >>appropriate behaviour, known to the producer and consumer, but not > >>the API that just forwards the error. > > > > > > Do you have this sketched out somewhere? > > // application level error handler, an instance of which > // is registered with the content handler > public class MyErrorHandler: IErrorHandler > { > public void Error(SAXError error) > { > // type cast that does not throw exception > MyAppError myError = error as MyAppError; ^^^ Cute! vvv > if (myError == null) { // not a MyAppError > log(error); > throw error.GetException(); > } > else { > myError.Recover(); > } > } > } > In this case the API (IErrorHandler) has no notion > of MyAppError.Recover(). SAX has few opportunities for error. Parsing has plentry of places to fail, and processing the events generated can fail. If there is a SAX exception, it is most likely a programming error. Since SAX is an event framework, I think the actual error is defined by the application, in it's own error exception heirarchy. For example, in one program, I'm using SAX to drive reflection to configure an XML pipeline. If I create an instance of a class, and find it doesn't support the Pipeable interface, I'm going to throw a NotAPipeableException. The NotAPipeableException isa SAXError. Rather, the SAXError is /caused by/ a NotAPipeableException. If I were to subsequently use JavaCC to write a grammar to configure my pipelines, I'd find that I'd have to include com.agtrz.sax.SAXError, simply to preserve my excpetion heirarchy. That is why I favor making SAXError a final class that is a container for the application defined exception. public void Error(SAXError error) { MyAppError myError = error.GetCause() as MyAppError; if (myError == null) { log(error); throw error.GetCause(); } else { myError.Recover(); } } Cheers. -- Alan Gutierrez - alan@e...
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|