代码之家  ›  专栏  ›  技术社区  ›  Dan

从Xalan捕获异常

  •  2
  • Dan  · 技术社区  · 14 年前

        try {
            TransformerFactory tf = TransformerFactory.newInstance();
            Source src = new SAXSource(new InputSource(new FileInputStream("doc.xsl")));
            Transformer t = tf.newTransformer(src);
            System.out.println(t);
        } catch (TransformerConfigurationException e) {
            System.out.println("the exception was " + e + " and its cause is " + e.getCause());
        }
    

    以及输出:

    com.sun.org.apache.bcel.internal.generic.ClassGenException: Branch target offset too large for short
    at com.sun.org.apache.bcel.internal.generic.BranchInstruction.dump(BranchInstruction.java:99)
    at com.sun.org.apache.bcel.internal.generic.InstructionList.getByteCode(InstructionList.java:980)
    at com.sun.org.apache.bcel.internal.generic.MethodGen.getMethod(MethodGen.java:616)
    at com.sun.org.apache.xalan.internal.xsltc.compiler.Mode.compileNamedTemplate(Mode.java:556)
    at com.sun.org.apache.xalan.internal.xsltc.compiler.Mode.compileTemplates(Mode.java:566)
    at com.sun.org.apache.xalan.internal.xsltc.compiler.Mode.compileApplyTemplates(Mode.java:818)
    at com.sun.org.apache.xalan.internal.xsltc.compiler.Stylesheet.compileModes(Stylesheet.java:615)
    at com.sun.org.apache.xalan.internal.xsltc.compiler.Stylesheet.translate(Stylesheet.java:730)
    at com.sun.org.apache.xalan.internal.xsltc.compiler.XSLTC.compile(XSLTC.java:354)
    at com.sun.org.apache.xalan.internal.xsltc.compiler.XSLTC.compile(XSLTC.java:429)
    at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:792)
    at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:614)
    at main.Main.main(Main.java:61)
    ERROR:  'Branch target offset too large for short'
    FATAL ERROR:  'Could not compile stylesheet'
    the exception was javax.xml.transform.TransformerConfigurationException: Could not compile stylesheet and its cause is null
    

    我要做的是捕获内部异常- ClassGenException -在我的密码里。在我的应用程序中,简单地将它打印到上面的STDERR是没有用的。有办法吗?

    1 回复  |  直到 14 年前
        1
  •  3
  •   Chris Lercher    14 年前

    您是否试图在TransformerFactory上设置错误侦听器?

        tf.setErrorListener(new ErrorListener() {
    
            @Override
            public void warning(TransformerException exception) throws TransformerException {
                ...
            }
    
            @Override
            public void fatalError(TransformerException exception) throws TransformerException {
                ...
    
            }
    
            @Override
            public void error(TransformerException exception) throws TransformerException {
                ...
    
            }
        });
    

    exception.getCause() .