Error in try-catch-finally

2019-02-20 13:48发布

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();
        }
    }
}

2条回答
叼着烟拽天下
2楼-- · 2019-02-20 14:11

Your catch block needs to be before the finally block.

查看更多
beautiful°
3楼-- · 2019-02-20 14:12

The catch comes before the finally block

查看更多
登录 后发表回答