Why is the two exception types in Java named “checked” and “unchecked”? What is the reason behind those names?
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.
If you call a method which is declared to throw a checked exception (such as
IOException), the compiler will check that you’re either catching it or declaring that you rethrow it. Likewise, in order to throw such a checked exception in the first place, the compiler checks that you’ve declared it as part of the method signature.Basically, it’s a little bit like type checking, except in terms of which exceptions can be thrown by a method.
The compiler doesn’t perform any checking for unchecked exceptions – so they can be thrown by any method, without the method declaring them.