Name
The ErrorHandler Interface
Synopsis
By passing an instance of the ErrorHandler
interface to the setErrorHandler( )
method of XMLReader
, you can provide custom
handling for particular classes of errors detected by the parser.
For example, you can choose to stop parsing when a validity error
is detected by throwing an exception from the error( )
method. The SAXParseException
passed to each of the
three methods in this interface provides details about the
specific cause and location of the error:
package org.xml.sax; public interfaceErrorHandler
{ public voidwarning
(SAXParseExceptionexception
) throws SAXException; public voiderror
(SAXParseExceptionexception
) throws SAXException; public voidfatalError
(SAXParseExceptionexception
) throws SAXException; }
Warnings represent possible problems noticed by the parser
that are not technically violations of XML’s well-formedness or
validity rules. For instance, a parser might issue a warning if an
xml:lang
attribute’s value was
not a legal ISO-639 language code. The most common kind of error
is a validity problem. The parser should report it, but it should
also continue processing. A fatal error violates well-formedness.
The parser should not continue parsing after reporting such an
error. Some parsers report violations of namespace well-formedness
as fatal errors. Others report these as nonfatal errors.
Get XML in a Nutshell, 3rd 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.