Can I catch multiple Java exceptions in the same catch clause?

This has been possible since Java 7. The syntax for a multi-catch block is: try { … } catch (IllegalArgumentException | SecurityException | IllegalAccessException | NoSuchFieldException e) { someCode(); } Remember, though, that if all the exceptions belong to the same class hierarchy, you can simply catch that base exception type. Also note that you cannot … Read more

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 … Read more