SAX/Java: Exceptions, Again

David Megginson ak117 at
Fri Jan 9 11:54:25 GMT 1998

James Clark writes:

 > The trouble with that approach is that that will have
 > to be declared as throwing Exception, which is horrible and will make
 > things ugly when application writers call run.  I want
 > to be declared as throwing (there's no way it can be
 > more restrictive that this).

Thank you again for the comments, James, and thank you for raising the
issue of exception handling in SAX in the first place.

I agree that at least has to be passed through,
but I think that there are some other ones, not derived from, that will be nearly as common.  For example, an
application writer could reasonably want to catch exceptions derived
from any of the following at the top level rather than in the


The last will be especially common, since I expect that SAX and the
JDBC will become very intimate friends.

>From a pragmatic perspective, the application writer will usually know
what exceptions (if any) her callbacks actually throw, and I am
allowing a parser (or at least, its SAX front end) to throw only, so the try-catch stuff around the parser
invocation should be fairly manageable -- this example, the user knows
that the callbacks throw MyException1 and MyException2 (the parser may
throw IOException as well):

  try {
    parser.parse(null, docUrl);
  } catch (MyException1 e) {
    /* do something */
  } catch (MyException2 e) {
    /* do something else */
  } catch ( e) {
    /* general */
  } catch (java.lang.Exception e) {
    // should never happen
    throw new Error("Unexpected exception! " + e.getMessage());

Finally, I don't want to rule out exceptions from important new Java
libraries over the next few years.

All the best,


David Megginson                 ak117 at
Microstar Software Ltd.         dmeggins at

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

More information about the Xml-dev mailing list