9.3 Error Messagesg

<..static void instructionErr(...)..>
 private static void instructionErr( Node node, String e, int num )
                                      throws Exception {
    String err = "--- xtpipes error " + num + " --- ";
    if( node != null ){
       err += "At <" + node.getNodeName();
       NamedNodeMap attr = node.getAttributes();
       for(int i=0; i<attr.getLength(); i++){
          Node nd = attr.item(i);
          err += " " +
              nd.getNodeName()  + "=\"" +
              nd.getNodeValue() + "\"" ;
       }
       err += " > : " ;
    }
    err += e;
    <.close ml2xml files.>
    Xtpipes.logWriter.flush();
    if( exceptionErrs ) { throw new Exception( err );  }
    else {
       System.err.println( err );
       System.exit(1);
    }
 }
 -_-_-

<..static void instructionErr(...)..>+
 private static void instructionErr( Node node, String e,
                                 StackTraceElement[] st, int num )
                                      throws Exception {
    Xtpipes.logWriter.println(
       "--- xtpipes error " + num + " --- " + e
    );
    for(int i=st.length-1; i>=0; i-- ){
       Xtpipes.logWriter.println( st[i].toString() );
    }
    instructionErr( node, e, num );
 }
 -_-_-

<..new ErrorHandler()..>
 new ErrorHandler() {
     public void warning(SAXParseException e) throws SAXParseException {
       showSpecifics("warning",e);
     }
     public void error(SAXParseException e) throws SAXParseException {
       showSpecifics("error",e);
     }
     public void fatalError(SAXParseException e) throws SAXParseException {
       showSpecifics("fatal error",e);
     }
     public void showSpecifics(String s, SAXParseException e)
                                                 throws SAXParseException {
       String err =   "--- xtpipes " + s + " 24 --- " + e.getSystemId()
                      + " line " + e.getLineNumber()
                      + " col "  + e.getColumnNumber()
                      + " : "    + e.getMessage() ;
       if( exceptionErrs ) { throw new SAXParseException(
                                      err, (org.xml.sax.Locator) null ); }
       else {
          System.err.println( err );
          System.exit(1);
 }   } }
 -_-_-

The follower listeners catch errors but their messages are not delivered through the call to the new exceptions (why?). The field errMssg is used so that error 16 will produce the same error messages.

Catches errors in the XSLT file

<..transformer factory XSLT error listener..>
 new ErrorListener() {
    public void warning(TransformerException e) throws TransformerException {
      showSpecifics(e);
    }
    public void error(TransformerException e) throws TransformerException {
      showSpecifics(e);
    }
    public void fatalError(TransformerException e) throws TransformerException {
      showSpecifics(e);
    }
    void showSpecifics(TransformerException e)
                                                throws  TransformerException{
      String err = e.getMessage() ;
      String loc = e.getLocationAsString();
      if( loc != null ){ err = loc + ": " + err; }
      err = "XSL stylesheet problem: " + err;
      if( errMssg == null ){ errMssg = err; }
      throw new TransformerException(err);
 }  }
 -_-_-

Catches errors in the XML file

<..transformer XML error listener..>
 new ErrorListener() {
    public void warning(TransformerException e) throws TransformerException {
      showSpecifics(e);
    }
    public void error(TransformerException e) throws TransformerException {
      showSpecifics(e);
    }
    public void fatalError(TransformerException e) throws TransformerException {
      showSpecifics(e);
    }
    void showSpecifics(TransformerException e)
                                                throws  TransformerException{
      String err = e.getMessage() ;
      String loc = e.getLocationAsString();
      if( loc != null ){ err = loc + ": " + err; }
      if( errMssg == null ){ errMssg = err; }
      err = "XML document prblem: " + err;
      throw new TransformerException(err);
 }  }
 -_-_-

<..identity transformer XML error listener..>
 new ErrorListener() {
    public void warning(TransformerException e) throws TransformerException {
      showSpecifics(e);
    }
    public void error(TransformerException e) throws TransformerException {
      showSpecifics(e);
    }
    public void fatalError(TransformerException e) throws TransformerException {
      showSpecifics(e);
    }
    void showSpecifics(TransformerException e)
                                                throws  TransformerException{
      String err = e.getMessage() ;
      String loc = e.getLocationAsString();
      if( loc != null ){ err = loc + ": " + err; }
      throw new TransformerException(err);
 }  }
 -_-_-

<..xtpipes fields..>+
 public static String errMssg;
 -_-_-