JAVA + try catch(FileNotFoundException e) going in catch(Exception e)?

It’s also possible that the specific issue you’re having isn’t a FileNotFoundException. By using the “Exception” in a catch block (which is the parent class to all Exceptions) this is effectively a “catch all”, since it will run if there is an `Exception or any of its subclasses thrown.

Try the following change:

...

catch (Exception e) {
  System.out.println(e.getClass());
}
...

This will tell you the specific class of the Exception being caught by this block. I’ll bet you’ll find that the Exception is actually an instance of a subclass (such as IOException, for example).

Leave a Comment