How can I know what exceptions can be thrown from a method?
exception, java
Solution
Look at the `throws` clause of a method signature to see what "checked" exceptions could be thrown. Callers of the method will have to propagate this information in their own `throws` clause, or handle the exception.
There is no 100% reliable way to know what `RuntimeException` or `Error` types 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 the `RuntimeException`. 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 `Error` is not caught. These indicate something seriously wrong with the runtime, such as insufficient memory.
Problem
How can I know what exceptions might be thrown from a method call?