Is checking for exceptions in code or using try-catch a better practice in Java?
exception, java, try-catch
Solution
To further Bozho's post checked exceptions typically handle exceptions you expect to happen regardless of how perfect your code is (ie: a network cable is unplugged and you catch and IO exception). You declare they methods throw checked exceptions as other code must deal with how to handle these exceptions.
Unchecked exceptions tend to be used for unexpected conditions for example NullPointerExceptions often bubble up because the program should have thrown a checked exception, filtered data, set defaults, etc. They are unchecked and often unexpected, thus you do not have to catch them.
This is not true 100% of the time but as a general approach that is how it works, in Java especially.
Problem
I had someone mention to me that catching all exceptions is not necessarily good practice (for example, NullPointerException). I am looking for an explanation of when this is a good thing, when it is not, and why it is as such :D Thanks!! badPanda