Custom Search

Monday 27 August 2012

Java Program that generates custom exception or user define exception, Write a java code to illustrate custom exception or user define exception


Java Program that generates custom exception or user define exception, Write a java code to illustrate custom exception or user define exception


Program
class negativeArgExc
{
public static void main(String args[])throws NegativeArgumentException
{
int i;
i=Integer.parseInt(args[0]);
if (i<0)
throw new NegativeArgumentException("Negative Commandline Argument");
}
}
class NegativeArgumentException extends Exception
{
public NegativeArgumentException(String str)
{
super(str);
}
}

No comments:

Post a Comment

Laptops