In the code below, Thread.sleep(3000);
written inside the anonymous class instantiation can be handled only using a try-catch block. Why doesn't the throws InterruptedException
clause allow the exception to propagate?
public static void main(String[] args) throws InterruptedException {
Runnable task = new Runnable() {
public void run() {
// below line explicitly need to be handled using try-catch. throws keyword does not work here
Thread.sleep(3000);
}
};
}