Error in try-catch-finally

淺唱寂寞╮ 提交于 2019-12-01 11:47:38

问题


I'm having problems, completing a try catch finally, I get through everything ok until the catches. My code errors on both saying "syntax error on "catch", for expected" and I've done a google search and haven't found something that worked. I've attached my code, is this simply a placement error, or am I not throwing the right type of error? thanks in advance.

    public void setOrder(String field, String value) {
    File dir = new File(finished);
    if (!dir.exists())
    {
        try{
            doc = PDDocument.load(file);
            PDDocumentCatalog docCatalog = doc.getDocumentCatalog();
            PDAcroForm acroForm = docCatalog.getAcroForm();
            PDField acrofield = acroForm.getField( field );
            if(value == null){
                acrofield.setValue("");
            }
            else{
                acrofield.setValue(value);
            }
            doc.save(finished);
        }
        finally{
            if( doc != null ){
                doc.close();
            }
        }
        catch(Exception eer){
            eer.printStackTrace();
        }
    }
    else{
        try{
            doc = PDDocument.load(finished);
            PDDocumentCatalog docCatalog = doc.getDocumentCatalog();
            PDAcroForm acroForm = docCatalog.getAcroForm();
            PDField acrofield = acroForm.getField( field );
            if(value == null){
                acrofield.setValue("");
            }
            else{
                acrofield.setValue(value);
            }
            doc.save(finished);
        }
        finally{
            if( doc != null ){
                doc.close();
            }
        }
        catch(Exception eer){
            eer.printStackTrace();
        }
    }
}

回答1:


The catch comes before the finally block




回答2:


Your catch block needs to be before the finally block.



来源:https://stackoverflow.com/questions/14593882/error-in-try-catch-finally

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!