title: How do I pass an error message generated by xslt to java application caller
body: <p>I use a java application to call a xslt to do a xml transformation. The xslt file will generate a message and terminate the process if some condition happens. However, my java application couldn't catch the error message generated by xslt, it only catch an exception with general information - "Stylesheet directed termination".</p>
  
  <p>Here is my java code:</p>
  
  <pre><code>SAXTransformerFactory saxTFactory = ((SAXTransformerFactory) tFactory);
      // Create a TransformerHandler for  stylesheet.
      File f2 = new File(styleSheetPath);
  </code></pre>
  
  <p>TransformerHandler tHandler2 = saxTFactory.newTransformerHandler(new StreamSource(f2));</p>
  
  <p>XMLReader reader = XMLReaderFactory.createXMLReader();</p>
  
  <pre><code>reader.setContentHandler(tHandler2);
  reader.setProperty("http://xml.org/sax/properties/lexical-handler", tHandler2);
  
      CharArrayWriter outputWriter  = new CharArrayWriter();
      Result result = new StreamResult(outputWriter);
      tHandler2.setResult(result);
  
      try
      {
        reader.parse(new InputSource(new StringReader(XMLinput)));
      }
      catch(Exception ee)
      {
          dsiplay(ee.getMessage())
          throw ee;
      }
  </code></pre>
  
  <p>How can I catch the error message from xslt?</p>
  
  <p>I tried to write a class:</p>
  
  <p>private class MyErrorHandler extends DefaultHandler{</p>
  
  <pre><code>  public void error(SAXParseException e)
    {
        System.out.println("error method "+e.getMessage());
    }
  
    public void fatalError(SAXParseException e)
    {
        System.out.println("fatal error method "+e.getMessage());
    }
  
    public void warning(SAXParseException e)
    {
        System.out.println("warning method "+e.getMessage());
    }
  </code></pre>
  
  <p>and </p>
  
  <pre><code>MyErrorHandler myHandler = new MyErrorHandler();
  
  reader.setErrorHandler(myHandler);
  </code></pre>
  
  <p>It didn't work.</p>
  
  <p>Do you have any suggestion? </p>