I wonder why it makes sense to have an empty try block followed by catching specific exception? Any thoughts?
try {
} catch (Exception e) {
// do nothing
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The idea is that unchecked exceptions can be thrown by any code, so if you’re catching something which can catch an unchecked exception, the compiler doesn’t check whether the code in the
tryblock can throw anything. In the special case where there really is no code in the try block, this is inappropriate – but it keeps the language simpler, and it’s only a problem in completely bogus code which I wouldn’t expect to show up in any real codebase. I guess there are similar situations where you’re only doing things with primitives etc, but it really is an edge case. Most try blocks will contain code which could theoreically throw an unchecked exception.If you try to catch a checked exception type which isn’t thrown in the
tryblock, then the compiler will complain.