[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: SAXException, checked, buy why?


checked excpetion
* 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!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.