Can some checked exceptions be converted to unchecked exceptions.
When I read the docs from
jms, I found some method convert checked exceptions into unchecked. I do not need to use “throws” anymore. Is this a feature of Java?
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.
You can also convert yourself exceptions from checked to unchecked:
where the fictional class
CheckedExceptionis the checked excetion that is thrown by the code within the dots, andUncheckedExceptionextendsRuntimeExceptionor one of its descendants.Without going into the checked vs unchecked exception debate, I would like to point out that is a good practice to convert exception as you go up with your abstraction layers, also your exception should be less specific about the implementation details.
For instance, if I’ve an interface PDFDocument with a method save(), it shouldn’t throw an IOException, because you could have an implementation saving to database, another to filesystem and a third saving to a remote site. Instead you could create your own exceptions or use one of the standard ones if it fits.