Documentation

Error Handling
Trail: Java API for XML Processing (JAXP)
Lesson: Processing Limits

Error Handling

It is recommended that applications catch the org.xml.sax.SAXNotRecognizedException exception when setting one of the new properties so that the applications will work properly on older releases that did not support them. For example, the downloadable sample code contains the following method, isNewPropertySupported, that detects if the sample is run with a version of the JDK that supports the JDK_GENERAL_ENTITY_SIZE_LIMIT property:

public boolean isNewPropertySupported() {
    try {
        SAXParser parser = getSAXParser(false, false, false);
        parser.setProperty(JDK_GENERAL_ENTITY_SIZE_LIMIT, "10000");
    } catch (ParserConfigurationException ex) {
        fail(ex.getMessage());
    } catch (SAXException ex) {
        String err = ex.getMessage();
        if (err.indexOf("Property '" + JDK_GENERAL_ENTITY_SIZE_LIMIT +
                                       "' is not recognized.") > -1) {
            //expected before this patch
            debugPrint("New limit properties not supported. Samples not run.");
            return false;
        }
    }
    return true;
}

When the input files contain constructs that cause an over-the-limit exception, applications may check the error code to determine the nature of the failure. The following error codes are defined for the limits:

The error code has the following format:

"JAXP" + components (two digits) + error category (two digits) + sequence number

The code JAXP00010001, therefore, represents the JAXP base parser security limit EntityExpansionLimit.


Previous page: Using the Limits
Next page: StAX