Is there a way to tell the Java compiler to not complain about a certain exception not being caught or thrown if I am 100% sure that the exception will never occur?
Share
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.
Assuming you mean checked exceptions, you can’t. Typically I would catch the exception, but propagate it into a
RuntimeException, e.g.You may very well want to create a specific exception for exactly this kind of scenario – while I wouldn’t suggest
WorldHasGoneMadExceptionfor the real name, something similar would be appropriate. This isn’t just “something unexpected has happened” but “wow, I would have bet good money that this really, really couldn’t happen”.Oh, and of course your unit tests won’t cover this case. Live with it 🙂