SAXON 9:错误监听器的fatalError异常在TransformerFactory.newFactory()调用期间从不冒泡

时间:2015-08-08 00:27:08

标签: java xml exception-handling saxon

如果包含的XML文件格式错误(即某处缺少标记闭包),我需要在fatalError的情况下冒出一个TransformerException。与规范相反,错误被完全抑制。这是一个纯XML问题,而不是XSL问题。

       <ul class="dropdown-menu" role="menu">
        <li><a href="#">My Company: {{ App\MyCompany::find(Session::get('my_company_id'))->name }}</a></li>
        <li><a href="#">My Branch: {{  App\MyBranch::find(Session::get('my_branch_id'))->name   }}</a></li>
        <li><a href="{{ URL::to('auth/reset') }}">{{ Lang::get("site/menu.reset_password") }}</a></li>
      </ul>

这是准系统错误监听器(为简洁起见,删除了几个方法):

try {
    TransformerFactory factory = TransformerFactory.newInstance();
    MyErrorListener errorListener = new MyErrorListener();
    factory.setErrorListener(errorListener);
    StreamSource ss = new StreamSource(new StringReader(badXslText), "file:" + xslPath);
    Transformer xf = factory.newTransformer(ss); // This is where MyErrorListener.fatalError below happens.. but that never bubbles up for some reason
    System.out.println("Nothing went wrong!");  // Yes it effing did!
} catch (TransformerException e) {
    //Why isn't this getting hit?
    String message = e.getMessage();
    throw new Exception("Problem during transform. "+message);
}

我差点把头发拉出来。

0 个答案:

没有答案