Code that triggers "Unreachable catch block for IIOException. This exception is never thrown from try statement"
int width = 0, height = 0;
BufferedImage img = null;
try {
try {
img = ImageIO.read(new File("target.png"));
String imgpath = "target.png";
} catch (IOException e) {
e.printStackTrace();
}
} catch (javax.imageio.IIOException e) {
try {
img = ImageIO.read(new File("target.jpg"));
String imgpath = "target.jpg";
} catch (IOException f) {
f.printStackTrace();
}
} finally {
if (img != null) {
width = img.getWidth();
height = img.getHeight();
}
}
And so I removed the catch statement involving the error:
try {
try {
img = ImageIO.read(new File("target.png"));
String imgpath = "target.png";
} catch (IOException e) {
e.printStackTrace();
}
} finally {
if (img != null) {
width = img.getWidth();
height = img.getHeight();
}
}
And now its triggering the error it said wouldn't trigger: "javax.imageio.IIOException: Can't read input file!"
What am I doing wrong