Saturday, 26 November 2016

Java Thread Exception.

Previously we have discussed about
Java Thread Exception

The call to sleep() method throws InterruptedException, so we enclosed in a try block and followed by a catch block ,because exception should be caught.If we fail to catch the exception ,program will not compile.

Java run system will throw IllegalThreadStateException whenever we attempt to invoke a method that a thread can not handle in the given state.

For Example : a sleeping thread can not deal with the resume() method because a sleeping thread can not recieve any instructions. The same is true with the suspend() method when it is used on a blocked (Non Runnable) thread.

Whenever we call a thread method that is likely to throw an exception, we have to supply an appropriate exception handler to catch it.The catch statement may take one of the following forms:

catch(ThreadDeath e){
----------
}
catch(InterruptedException e){
----------
}
catch(IllegalArgumentException e){
----------
}
catch(Exception e){
-----------
}

      
Blog Author - Pushkar Khosla,
Software Developer by Profession with 3.0 Yrs of Experience , through this blog i'am sharing my industrial Java Knowledge to entire world. For any question or query any one can comment below or mail me at pushkar.itsitm52@gmail.com.

This blog is all about to learn Core Java ,Interview Programs and Coding tricks to polish your Java Knowledge. If you like the content of this blog please share this with your friends.



No comments:

Post a Comment