SAX: Exceptions in Java SAX Implementation

David Megginson ak117 at freenet.carleton.ca
Thu Jan 8 02:38:38 GMT 1998


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 at freenet.carleton.ca
Microstar Software Ltd.         dmeggins at microstar.com
      http://home.sprynet.com/sprynet/dmeggins/

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




More information about the Xml-dev mailing list