public interface ErrorReport extends ErrorHandler
All errors are reported, stored and retrieved as SAX exceptions. Errors reported by a parser are likely to derive from SAXException, but the application should not assume all errors extend this class.
Some applications are interested in stopping at the first error and can request that the parsing/processing throw a SAX exception at the first error (not warning) they encounter. Other applications are interested in recovering from as many errors as possible, with only fatal errors stopping the parsing/processing. The application can then obtain an ordered list of errors including their location and description, for example, for the purpose of printing a log or error list in a GUI component.
When used with the OpenXML parser and compatible processors, each error is given a level number. Two parameters are used to control response to errors at different levels.
The report level determines which errors are to be recorded and reported back to the application. The three most common values are REPORT_WITH_WARNING which reports all errors and warnings, REPORT_ALL_ERRORS which reports all errors but no warnings, and REPORT_NOTHING which supresses reporting.
The stop level determines which error level will stop the parser/processor by throwing a SAX exception. The three most common values are STOP_AT_NO_ERROR which will only stop if a fatal error is encountered (fatal errors are non recoverable), STOP_AT_FIRST_ERROR which will stop at the first error encountered, and STOP_AT_CONTENT which will swallow all parsing errors, but stop at a content, processing or general error.
When used with any other parser or SAX event driver processor, all errors are reported at GENERAL level, so the STOP_AT_CONTENT resolution is meaningless.
Once errors have been accumulated, they can be retrieved by the application in a variety of ways. The application should always be interested in the last error recorded, if no exception was thrown. The application can retrieve the error list one by one, either as exceptions, formatted messages, or error level. The application can also request an array of errors (exceptions or formatted messages) at a given level.
The formatting of the error message consists of the error location, it's level and it's message. When parsing the location is likely to include the document's name (system identifier), line number and column within the line. When processing the location is likely to include a node or element's location in the document tree.
ErrorHandler, SAXException| Modifier and Type | Field and Description |
|---|---|
static int | CONTENTDocument content error. |
static int | FATALFatal error after which processing cannot continue. |
static int | GENERALGeneric error. |
static int | PROCESSINGGeneric document processing error. |
static int | REPORT_ALL_ERRORSReport all errors but no warnings. |
static int | REPORT_NOTHINGIgnore all errors, nothing is reported. |
static int | REPORT_WITH_WARNINGReport all errors and warnings. |
static int | STOP_AT_CONTENTStop at first content error. |
static int | STOP_AT_FATALStop at fatal error only. |
static int | STOP_AT_FIRST_ERRORStop at error encountered. |
static int | STOP_AT_NO_ERRORStop at no error (except fatal). |
static int | STOP_AT_PROCESSINGStop at first processing error. |
static int | STOP_AT_VALIDITYStop at first validity error. |
static int | STOP_AT_WELL_FORMEDStop at first well formed error. |
static int | VALIDITYDocument validity error. |
static int | WARNINGWarning. |
static int | WELL_FORMEDWell formed document error level. |
| Modifier and Type | Method and Description |
|---|---|
void | fatalError(Exception except)Report a fatal exception derived from an exception. |
int | getCount()Returns the number of errors contained in this report. |
int | getErrorLevel(int index)Returns the error level of the numbered error. |
SAXException | getException(int index)Returns the error's exception. |
SAXException | getLastException()Return the last error exception. |
String | getLastMessage()Return the last error as formatted message. |
String | getMessage(int index)Returns formatted error message. |
boolean | isReporting(int errorLevel)True if errors in this level are to be reported. |
SAXException[] | listExceptions(int fromErrorLevel)Returns a list of error exceptions. |
String[] | listMessages(int fromErrorLevel)Returns a list of error messages. |
void | reportError(int errorLevel, Node node, SAXException except)Report a processing error at the specified level. |
void | reportError(int errorLevel, SAXException except)Report a parse error at the specified level. |
void | reportError(int errorLevel, String location, SAXException except)Report a processing error at the specified level. |
error, fatalError, warningstatic final int WARNING
static final int WELL_FORMED
static final int VALIDITY
static final int CONTENT
static final int PROCESSING
static final int GENERAL
This is the default error level, if none is specified (e.g. when using this report as a SAX error handler).
static final int FATAL
static final int REPORT_WITH_WARNING
static final int REPORT_ALL_ERRORS
static final int REPORT_NOTHING
STOP_AT_FIRST_ERROR but is not interested in warnings. We do not recommend a) as an approach to application design.static final int STOP_AT_WELL_FORMED
This level is used when the document must be correct, or else there is no point in handling it.
static final int STOP_AT_VALIDITY
This level is used when the document must be valid, or else there is no point in handling it.
static final int STOP_AT_CONTENT
static final int STOP_AT_PROCESSING
static final int STOP_AT_FATAL
This level is used when the application assumes that all errors can be properly corrected, or when the application reports all errors not just the last one.
static final int STOP_AT_FIRST_ERROR
This level is equivalent to STOP_AT_WELL_FORMED.
static final int STOP_AT_NO_ERROR
This level is equivalent to STOP_AT_FATAL.
void reportError(int errorLevel,
String location,
SAXException except)
throws SAXExceptionerrorLevel - The error level to reportlocation - The location at which the error occuredexcept - The exception to be reportedSAXException - Will throw the exception if set to stop at this error levelvoid reportError(int errorLevel,
Node node,
SAXException except)
throws SAXExceptionerrorLevel - The error level to reportnode - The document tree node at which the error occuredexcept - The exception to be reportedSAXException - Will throw the exception if set to stop at this error levelvoid reportError(int errorLevel,
SAXException except)
throws SAXExceptionerrorLevel - The error level to reportexcept - The exception to be reportedSAXException - Will throw the exception if set to stop at this error levelvoid fatalError(Exception except) throws SAXException
except - The exception to be reported as fatalSAXException - The exception is reported and thrown as this SAX exceptionboolean isReporting(int errorLevel)
errorLevel - The error level to be reportedSAXException getLastException()
String getLastMessage()
String[] listMessages(int fromErrorLevel)
WARNING.fromErrorLevel - Return only errors of this or higher error levelSAXException[] listExceptions(int fromErrorLevel)
WARNING.fromErrorLevel - Return only errors of this or higher error levelint getCount()
SAXException getException(int index)
SAXException exception, SAXParseException if the error was generated by a parser.index - The error message numberString getMessage(int index)
index - The error message numberint getErrorLevel(int index)
index - The error message numberPhantom® and NetPhantom® are registered trademarks of Mindus SARL.
© 2026 Mindus SARL. All rights reserved.