Wednesday, March 11, 2009

Exception Example(Throw and Throws )

class MyExp extends Exception
{
public MyExp(String msg)
{
System.out.println(msg);
}
}

public class throws1 {
static int mtd(int a,int b) throws MyExp
{
if(b==0) throw new MyExp("Example for throw b") ;
else
if(a==0) throw new MyExp("Example for throw a") ;
return a/b;
}
public static void main(String args[])
{
try
{
System.out.print(mtd(10,0));
}
catch(Exception e)
{
System.out.println(e);
}
}
}

No comments:

Post a Comment