不会抛出异常

时间:2015-02-11 16:36:42

标签: java

我正在检查文件夹和文件的目录,然后更新最终显示它们的方法。我无法让try catch块工作。根据作业的指示需要它。输入正确的文件路径后,信息将按预期显示。输入错误的路径时,我没有按预期获得JOptionPane。我使用正确的语法来查找错误的路径吗?我是如何设置try catch块的还是错误的?

public void viewDirectoryContents(String basePath) {
    try {
// new file path 
        File file = new File(basePath);
// basePath sent to updateDirectory() for display
        updateDirectory(file);
        if (!new File(basePath).exists())
            ;
        {
            throw new FileNotFoundException("The path " + basePath
                    + " does not exist or the cancel button was clicked");
        }
    } catch (FileNotFoundException e) {
        JOptionPane.showMessageDialog(null, e);
    }
}

1 个答案:

答案 0 :(得分:7)

删除终止if语句的分号

if (!new File(basePath).exists());
                                 ^