赶不上尝试

时间:2019-03-04 20:56:01

标签: java try-catch

当我在cmd中执行此servlet时出现问题,显示错误:'catch' 没有“尝试”      捕获(XQException e){

如果您在我的servlet中发现错误,我将不胜感激

public void doGet(HttpServletRequest request, HttpServletResponse response) 
throws ServletException, IOException{
try  {

    response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        ServletContext context = getServletContext();  
        XQDataSource ds = new SaxonXQDataSource();
        XQConnection conn = ds.getConnection();                      
    String xqueryRequest="for $t in doc('/WEB- 
    INF/theatre.xml')/theatres/theatre"+
    "order by $t/nom"+
    "return"+
    "<theatres>"+
    "<theatre>"+
    "{$t/nom}"+
    "{$t/adresse}"+
    "</theatre>"+
    "</theatres>";
  InputStream xsl = (InputStream)(context.getResourceAsStream("/WEB- 
  INF/theatre.xsl"));
        Source xslDoc3 =  new StreamSource(xsl);

      XQPreparedExpression exp = conn.prepareExpression(xqueryRequest);  
        XQResultSequence result = exp.executeQuery(); 

        while (result.next()) {  
            out.println(result.getItemAsString(null));  
        }   

    StringWriter swr3 = new StringWriter();
    out.println(swr3.toString());
    out.close();
    }
    catch(Exception ex1){
    ex1.printStackTrace();
    }
     catch (FileNotFoundException e) {  
        e.printStackTrace();  
    }
      finally{
    catch (XQException e) {  
        e.printStackTrace();  
    } 
      }

}
}

那么,您能帮我吗?并感谢大家。

1 个答案:

答案 0 :(得分:1)

简单:尝试一下后,finally块中的陷阱就不会出现!

没关系在这里终于尝试之前没有关系! finally关键字“结束”属于初始try语句的catch块列表。因此,finally块中的渔获量是一个“孤儿”,它缺少先前的尝试。