Name

ErrorHandler

Synopsis

Before parsing an XML document, an application should provide an implementation of this interface to the XMLReader by calling the setErrorHandler( ) method of the XMLReader. If the reader needs to issue a warning or report an error or fatal error, it will call the appropriate method of the ErrorHandler object you supplied. The error( ) method is used to report recoverable errors, such as document validity problems. The parser continues parsing after calling error( ). The fatalError( ) method is used to report nonrecoverable errors, such as well-formedness problems. The parser may not continue parsing after calling fatalError( ). An ErrorHandler object may respond to warnings, errors, and fatal errors however it likes, and may throw exceptions from these methods.

Instead of implementing this interface directly, you may also subclass the helper class org.xml.sax.helpers.DefaultHandler and override the error reporting methods it provides. The warning( ) and error( ) methods of a DefaultHandler do nothing, and the fatalError( ) method throws the SAXParseException object that was passed to it.

public interface ErrorHandler {
// Public Instance Methods
     void error(SAXParseException exception) throws SAXException;  
     void fatalError(SAXParseException exception) throws SAXException;  
     void warning(SAXParseException exception) throws SAXException;  
}

Implementations

HandlerBase, org.xml.sax.helpers.DefaultHandler, org.xml.sax.helpers.XMLFilterImpl

Passed To

javax.xml.parsers.DocumentBuilder.setErrorHandler( ...

Get Java in a Nutshell, 5th Edition 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.