public class TaggedContentHandler extends ContentHandlerDecorator
TaggedSAXException
class to wrap all thrown
SAXException
s. See below for an example of using this class.
TaggedContentHandler handler = new TaggedContentHandler(...); try { // Processing that may throw an SAXException either from this handler // or from some other XML parsing activity processXML(handler); } catch (SAXException e) { if (handler.isCauseOf(e)) { // The exception was caused by this handler. // Use e.getCause() to get the original exception. } else { // The exception was caused by something else. } }
Alternatively, the throwIfCauseOf(Exception)
method can be
used to let higher levels of code handle the exception caused by this
stream while other processing errors are being taken care of at this
lower level.
TaggedContentHandler handler = new TaggedContentHandler(...); try { processXML(handler); } catch (SAXException e) { stream.throwIfCauseOf(e); // ... or process the exception that was caused by something else }
TaggedSAXException
Constructor and Description |
---|
TaggedContentHandler(ContentHandler proxy)
Creates a tagging decorator for the given content handler.
|
Modifier and Type | Method and Description |
---|---|
protected void |
handleException(SAXException e)
Tags any
SAXException s thrown, wrapping and re-throwing. |
boolean |
isCauseOf(SAXException exception)
Tests if the given exception was caused by this handler.
|
void |
throwIfCauseOf(Exception exception)
Re-throws the original exception thrown by this handler.
|
characters, endDocument, endElement, endPrefixMapping, ignorableWhitespace, processingInstruction, setContentHandler, setDocumentLocator, skippedEntity, startDocument, startElement, startPrefixMapping, toString
error, fatalError, notationDecl, resolveEntity, unparsedEntityDecl, warning
public TaggedContentHandler(ContentHandler proxy)
proxy
- content handler to be decoratedpublic boolean isCauseOf(SAXException exception)
exception
- an exceptiontrue
if the exception was thrown by this handler,
false
otherwisepublic void throwIfCauseOf(Exception exception) throws SAXException
TaggedSAXException
wrapper created by this decorator, and then unwraps and throws the
original wrapped exception. Returns normally if the exception was
not thrown by this handler.exception
- an exceptionSAXException
- original exception, if any, thrown by this handlerprotected void handleException(SAXException e) throws SAXException
SAXException
s thrown, wrapping and re-throwing.handleException
in class ContentHandlerDecorator
e
- The SAXException thrownSAXException
- if an XML error occursCopyright © 2007-2015 The Apache Software Foundation. All Rights Reserved.