SAX Error Handling
Most SAX interface methods throw SAXException. SAXException extends java.lang.Exception and adds one fundamental feature, which is the ability to piggyback an arbitrary exception inside of a SAXException. This allows implementations to propagate non-SAX-related exceptions across SAX interface method boundaries. Consider the following implementation of ContentHandler.characters:
void characters(char[] ch, int offset, int length) throws org.xml.sax.SAXException { try { this.out.write(ch, offset, length); } catch (java.io.IOException ex) { throw new org.xml.sax.SAXException(ex); } }
This implementation embeds a java.io.IOException inside the SAXException that it is required to throw. Callers can then scrape out the exception ...
Get Essential XML: Beyond Markup now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.