Explain Thread exceptions?


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
}

Related

What is Type casting in Java?

Some   times there  are  a  need to store a  value  of  one type  in to variable of  another  type.In such situations  we  must ...

Basic Concept’s of Object Oriented Programming

Basic   concept’s  of Object Oriented Programming : Object:- Objects  are basic  run time  entities  in an  object  orient...

Features of Java

Java is  simple  and  familiar   program  language:- learning and practicing java  is easy because it contains many features of c and c++. Java is  s...

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

item