I have a command that creates a file on disk. Since the folder in which the file is to be created is dynamic, I have a catch (FileNotFoundException e). In the same try block, I already have a catch block (Exception e). For some reason, when I run my code and the folder does not exist yet, the catch block (Exception e) is used, not the FileNotFoundException file.
The debugger is clear though (at least for me), showing FileNotFoundException: java.io.FileNotFoundException: c: \ mydata \ 2F8890C2-13B9-4D65-987D-5F447FF0DDA7 \ filename.png (the system cannot find the path specified)
Any idea why it is not included in the FileNotFoundException block? Thanks;
CODE:
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; }
source share