Throw and throws

What is the difference between throw and throws

Questions by kulkarni85

Showing Answers 1 - 6 of 6 Answers

ravi_1229

  • Mar 24th, 2008
 

if user program explicitly wants to throw an exception(inbuilt or userdefined) then throw keyword is used.
if the user program wants to throw an exception in a particular condition then throw
  keyword is used
metho(){
...........................
if(age>100){
    new AgeBarException();
}else{
    <write code>
}
}

if the user dont want to handle the exceptions , he can throws the exceptions using

public void myMethod() throws Exception{
vector.add("9099");
}
the above method throws an exception which is not handled .

if another user uses the myMethod he have to handle that exception using try....catch...block
:)
 

  Was this answer useful?  Yes

ravi_1229

  • Mar 24th, 2008
 

if user program explicitly wants to throw an exception(inbuilt or userdefined) then throw keyword is used.
if the user program wants to throw an exception in a particular condition then throw
  keyword is used
metho(){
...........................
if(age>100){
   throw  new AgeBarException();
}else{
    <write code>
}
}

if the user dont want to handle the exceptions , he can throws the exceptions using

public void myMethod() throws Exception{
vector.add("9099");
}
the above method throws an exception which is not handled .

if another user uses the myMethod he have to handle that exception using try....catch...block
:)
 

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions