What is the difference between throw and throws

Showing Answers 1 - 2 of 2 Answers

Kulwant

  • Sep 12th, 2005
 

throw is used to explicitly thorw some exception

throws is used to tell the compiler the this method might through mentioned type of exception.

  Was this answer useful?  Yes

form practicing java point of view , here is in brief what is the difference


you have function that do a mathematical division and may be a a division by zero exception raises up, so you need to tell anybody uses this function to handle this exception so you throws this exception from your function

public float yourFunction() throws ArithemeticException{
//function body


}

and if you want to rethrow or throw and exception to be propagated to the next handler, or throw your own Exception

try{

}Catch(Exception e){

throw e;
throw YourException();
}

  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