hi firiends what is difference between throw and throws keywords in java exception handling:)
Printable View
hi firiends what is difference between throw and throws keywords in java exception handling:)
Hi kuklkarni,
[B]Throws[/B] :- it is used to specify method level excetpion,to specify some statements in side a method level, when we are calling this type of methods we must handle the exceptions thrown by statements in the method.
eg :- public class ThrowEeg{
void m1() throws Exception
{
sop("");
a= a/0;
sop(a);//this line throws Exception.
sop(""); //this line dose n't excute
}
public static void main(String arg[])
{
ThrowEeg thre = new ThrowEeg();
try{ //here we call the try statement.
thre.m1();//method calling here.
}
catch(Exception e){
sop(e);
}
}
[B]Throw[/B] :- it is generally use with user defined exceptions.to manually throw an exception use this key word.