Explain Thread exceptions?

https://www.computersprofessor.com/2016/12/explain-thread-exceptions.html
|
Sleep method is enclosed in a try blocked followed by a catch
block.
|
This is necessary because the sleep( ) throws an exception, which
should be caught .if we fail to catch the exception ,program will not compile.
|
Java run system will throw IllegalThreadStateException whenever we
attempt to involve a method that a thread cannot handle in the given state.
|
For ex: a sleeping thread
cannot deal with the resume( ) method because a sleeping thread can not
receive any instructions. The same is true with the suspend() method when it
is used on a blocked thread.
|
When ever we call a thread method that is likely to throw an
exception. we have to supply an appropriate exception handle to catch it.
The catch statement may take one of the following forms.
catch(ThreadDeath e)
{
………………
//killed thread
}
catch(InterruptedException e)
{
………….. //cannot handle it
in the current state
}
catch(IllegalArgumentException e)
{
…………………………….. //illegal
method argument
}
catch(Exception e)
{
…………………. //any other
}
|