exception handling in core java




Asked on November 06, 2013
what is the difference between the throws and throw. i have read from internet but the point is not clear to me.


Replied on November 06, 2013
throw : throws one exception object when desired anywhere in the program. Ex 
If(b==0){
  throw new Exception("Some error");
}

throws: throws keyword is used at method level. We can mention more than one exception type as comma separated and whatever exception will be applicable, will be thrown by method. Ex. 

public void cal() throws FileNotFoundException, MalformedURLException {} 



Replied on November 06, 2013

Write Answer











©2024 concretepage.com | Privacy Policy | Contact Us