Java Exceptions | SoloLearn: Learn to code for FREE!


Java Exceptions

Should I map NoSuchFileException to file to FileNotFoundException ? or Should I use FileNotFoudnException instead of NoSuchFileException because it is more specific?

10/29/2017 8:27:52 AM

Wasula Benjamin

1 Answer

New Answer


I'd say you should go for the most specific exception, because it allows you for example to show a better error message for the user with instructions how to handle the exception. But if you don't need that kind of error handling or don't handle the error at all, you don't need to handle the lowest level exception. Then your program can show a message like: 'Something went wrong, I won't tell you what. But you can try it again if you dare.' I guess you'll get the point ;)