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

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   SAX: Exceptions in Java SAX Implementation

[ Lists Home | Date Index | Thread Index ]
  • From: David Megginson <ak117@freenet.carleton.ca>
  • To: xml-dev Mailing List <xml-dev@ic.ac.uk>
  • Date: Wed, 7 Jan 1998 21:38:23 -0500

ISSUE: LANGUAGE-SPECIFIC EXCEPTION HANDLING

I think that it would be a bad idea for SAX to require the target
language to support exceptions; as a result, I don't plan to require
any of the SAX interfaces to throw specific exceptions under specific
circumstances (though exceptions like java.io.IOException or
java.net.MalFormedURLException may be thrown by code outside of SAX).
I may, however, create an exception specifically for use with the
error() implementation in the base class, for languages that support
exceptions.

More generally, SAX users for the Java version will almost certainly
want to be able to pass their own exceptions (such as database access
exceptions) through from their event handlers to the code that started
the parser, and that means that exceptions will have to flow through
the event handlers and the SAX parser more-or-less transparently.
Does it make sense, then, simply to allow every method in the SAX/Java
interfaces to throw java.lang.Exception?

  package org.xml.sax.DocumentHandler {
    public void startDocument () throws java.lang.Exception;
    public void endDocument () throws java.lang.Exception;
    /* etc. */
  }

The parser itself could intercept any exceptions that it knows about
specifically, and simply pass through the rest to the caller.  An
invocation of a SAX parser in Java, then, would probably look
something like this:

  try {
    parser.parse(null, "file://localhost/home/david/foo.xml");
  } catch (IOException e) {
    /* do something */
  } catch (MyException e) {
    /* do something else */
  } catch (Exception e) {
    /* do yet another thing */
  }

We are simply passing through exceptions for languages that support
them: languages without exceptions can simply omit this facility
without damaging the functionality of SAX.

Thanks to James Clark for raising this point a week or two ago.  I
would appreciate in particular hearing from Java and other OO design
specialists on the merits (or otherwise) of this approach.


Thanks, and all the best,


David

-- 
David Megginson                 ak117@freenet.carleton.ca
Microstar Software Ltd.         dmeggins@microstar.com
      http://home.sprynet.com/sprynet/dmeggins/

xml-dev: A list for W3C XML Developers. To post, mailto:xml-dev@ic.ac.uk
Archived as: http://www.lists.ic.ac.uk/hypermail/xml-dev/
To (un)subscribe, mailto:majordomo@ic.ac.uk the following message;
(un)subscribe xml-dev
To subscribe to the digests, mailto:majordomo@ic.ac.uk the following message;
subscribe xml-dev-digest
List coordinator, Henry Rzepa (mailto:rzepa@ic.ac.uk)





 

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

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