OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   Re: [xml-dev] SAXException, checked, buy why?

[ Lists Home | Date Index | Thread Index ]

* Karl Waclawek <karl@waclawek.net> [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@engrm.com




 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS