Code example for SAXParseException

Methods: getColumnNumber, getException, getLineNumber, getMessage, getSystemId

0
 
        } catch (SAXParseException e) {
            if (e != fatal) {
                System.err.print (printParseException ("Parsing Aborted", e));
                e.printStackTrace ();
                if (e.getException () != null) {
                    System.err.println ("++ Wrapped exception:");
                    e.getException ().printStackTrace ();
                } 
            } 
 
        } catch (SAXException e) {
            Exception   x = e;
            if (e.getException () != null)
                x = e.getException ();
            x.printStackTrace ();
 
        } catch (Throwable t) {
            t.printStackTrace ();
        } 
 
        System.exit (exitStatus);
    } 
 
    // returns true if saw a validator (before end or unrecognized node) 
    // false otherwise 
    private static boolean hasValidator (EventConsumer e)
    { 
        if (e == null)
            return false; 
        if (e instanceof ValidationConsumer)
            return true; 
        if (e instanceof TeeConsumer) {
            TeeConsumer t = (TeeConsumer) e;
            return hasValidator (t.getFirst ())
                || hasValidator (t.getRest ());
        } 
        if (e instanceof WellFormednessFilter
                || e instanceof NSFilter
                ) 
            return hasValidator (((EventFilter)e).getNext ());
 
        // else ... gee, we can't know.  Assume not. 
 
        return false; 
    } 
 
    static class MyErrorHandler implements ErrorHandler
    { 
        // dump validation errors, but continue 
        public void error (SAXParseException e)
        throws SAXParseException 
        { 
            errorCount++;
            System.err.print (printParseException ("Error", e));
        } 
 
        public void warning (SAXParseException e)
        throws SAXParseException 
        { 
            // System.err.print (printParseException ("Warning", e)); 
        } 
 
        // try to continue fatal errors, in case a parser reports more 
        public void fatalError (SAXParseException e)
        throws SAXParseException 
        { 
            fatalCount++;
            if (fatal == null)
                fatal = e;
            System.err.print (printParseException ("Nonrecoverable Error", e));
        } 
    } 
 
    static private String printParseException (
        String                  label,
        SAXParseException       e
    ) { 
        CPStringBuilder buf = new CPStringBuilder ();
        int             temp;
 
        buf.append ("** ");
        buf.append (label);
        buf.append (": ");
        buf.append (e.getMessage ());
        buf.append ('\n');
        if (e.getSystemId () != null) {
            buf.append ("   URI:  ");
            buf.append (e.getSystemId ());
            buf.append ('\n');
        } 
        if ((temp = e.getLineNumber ()) != -1) {
            buf.append ("   line: ");
            buf.append (temp);
            buf.append ('\n');
        } 
        if ((temp = e.getColumnNumber ()) != -1) {
            buf.append ("   char: ");
            buf.append (temp);
            buf.append ('\n');
        }