What is the exception thrown by Thread.sleep(int milli) method? Why does Thread.sleep() method throws that exception?
ThreadSleepException. It throws that exception because it is sleeping.
InterruptedException. It throws that exception because it may be interrupted by other threads while sleeping.
both option 1 and 2 are right.
it won't throw any exception.
Thread.sleep() will throw InterruptedException.
This exception is thrown when a thread is in sleep mode, and other thread tries to interrupt it by calling interrupt() method on that thread object.
It is mandatory that programmer has to handle this exception either by using try-catch block or by using throws.
Back To Top