Thus, you declare the exceptions that can be thrown within the scope of a Java methods in the method signature. The next page, Dealing with Exceptions , talks about declaring exceptions and shows you how to declare exceptions for Java methods that require it. Of interest to us in this discussion are runtime exceptions. Runtime exceptions are those exceptions that occur within the Java runtime system. This includes arithmetic exceptions, such as when dividing by zero, pointer exceptions, such as trying to access an object through a null reference, and indexing exceptions, such as attempting to access an array element through an index that is too large or too small.
Runtime exceptions can occur anywhere in a program and in a typical program can be very numerous.
Often the cost of checking for runtime exceptions exceeds the benefit of catching or declaring them. Thus the compiler does not require that you catch or declare runtime exceptions, though you can. Often, this is considered a loophole in Java's exception handling mechanism and programmer's are tempted to declare all exceptions to be runtime exceptions. In general, this is not recommended. The Controversy contains a thorough discussion about when and how to use runtime exceptions.