java 进入catch,JAVA + try catch(FileNotFoundException e)进入catch(Exception e)?
我有一些在磁盤上創建文件的命令。
因為要創建文件的文件夾是動態的,所以我有一個catch(FileNotFoundException e)。在同一個try塊中,我已經有一個catch(Exception e)塊。
出于某種原因,當我運行我的代碼并且該文件夾尚不存在時,使用catch(Exception e)塊,而不是FileNotFoundException。
調試器很清楚(至少對我來說),顯示FileNotFoundException:java.io.FileNotFoundException:c:\ mydata \ 2F8890C2-13B9-4D65-987D-5F447FF0DDA7 \ filename.png(系統找不到指定的路徑)
任何想法為什么它沒有進入FileNotFoundException塊?
謝謝;
碼:
import java.io.FileNotFoundException;
try{
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Rectangle screenRectangle = new Rectangle(screenSize);
Robot robot = new Robot();
BufferedImage image = robot.createScreenCapture(screenRectangle);
ImageIO.write(image, "png", new File(fileName));
}
catch (FileNotFoundException e){
// do stuff here..
return false;
}
catch(Exception e){
// do stuff here..
return = false;
}
總結
以上是生活随笔為你收集整理的java 进入catch,JAVA + try catch(FileNotFoundException e)进入catch(Exception e)?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php 注册回调函数,PHP回调函数
- 下一篇: Java中return结束循环,Java