How can I know what exceptions might be thrown from a method call?
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.
Look at the
throwsclause of a method signature to see what “checked” exceptions could be thrown. Callers of the method will have to propagate this information in their ownthrowsclause, or handle the exception.There is no 100% reliable way to know what
RuntimeExceptionorErrortypes can be thrown. The idea is that these types are unlikely to be recoverable. It is common to have a high-level exception handler act as a “catch-all” to log, display, or otherwise report theRuntimeException. Depending on the type of application, it might exit at that point, or keep running.Some APIs do document runtime exceptions they might throw with JavaDoc tags, just like a checked exception. The compiler does not enforce this, however.
In general, an
Erroris not caught. These indicate something seriously wrong with the runtime, such as insufficient memory.