Click to See Complete Forum and Search --> : [RESOLVED] does sleep() throw Interrupted Exception


vaishnavi
03-11-2009, 06:15 AM
Hi All,

I am bit confused about the way sleep() and InterruptedException works. While using sleep(), is it mandatory to use InterruptedException? As far as I know, we should use the exception, but the following code works fine even without the exception which confuses me.

public class exceptiondemo
{
public static void main(String args[])throws Exception
{
Thread.sleep(3000);
System.out.println("sleep");
}
}

chazzy
03-12-2009, 09:09 PM
because you have Exception in your throws clause.

vaishnavi
03-13-2009, 11:33 AM
Chazzy,

Thanks for your reply. That solved my question.