0

Java Exceptions

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

29th Oct 2017, 8:27 AM
Wasula Benjamin
Wasula Benjamin - avatar
1 Réponse
+ 11
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 ;)
29th Oct 2017, 10:49 AM
Tashi N
Tashi N - avatar