There are two kinds of exceptions in Java: checked and unchecked exceptions.
For the noted exceptions, the compiler checks whether your program processes them either by searching for them, or by specifying (with the throws ) a method in which an exception may occur that the method may cause such an exception.
The exception classes, which are subclasses of java.lang.RuntimeException (and the RuntimeException themselves), are thrown exceptions. For these exceptions, the compiler does not check - so you do not need to catch them or indicate that you can throw them.
The InterruptedException class is a checked exception, so you must either catch it or declare that your method can throw it. You throw an exception from the catch , so you must indicate that your method can throw it:
public void invalid() throws InterruptedException {
Exception classes that extend java.lang.Exception (except for RuntimeException and subclasses) are checked by exceptions.
See the Sun Java Exception Tutorial for more details.
Jesper
source share