class ThreadSleep extends
Thread
{
public void run()
{
System.out.println("begining run");
for(int i=0;i<=5;i++)
{
System.out.println("i="+i);
try{
Thread.sleep(1000); //generating Checked Exception: InterruptedException
}
catch(InterruptedException ie){
System.out.println("handled successfully ");
}
}
System.out.println("end of run");
}
public static void main(
String s[])
{
ThreadSleep ts=new ThreadSleep();
System.out.println("begining main");
ts.start();
for(int j=0;j<=5;j++)
{
System.out.println("j="+j);
}
System.out.println("end main");
}
}
After executing,the prog is successfully executed. But i found that the catch block is not executing.
Why is that, is the catch block not able to handle the exception ? the outputis as follows:
begining main
j=0
j=1
j=2
j=3
j=4
j=5
end main
begining run
i=0
i=1
i=2
i=3
i=4
i=5
end of run
where is the statement: "handled successfully" ?