class MyException extends Exception
{
private int salary;
MyException(int s)
{
salary=s;
}
public String toString()
{
return "MyException[" + salary +"]";
}
}
class ExceptionDemo
{
static void compute(int s) throws MyException
{
System.out.println("main exception(" + s + ")");
if((s>60000)&&(s<20000))
throw new MyException(s);
System.out.println("no exception");
}
public static void main(String args[])
{
try
{
int s=Integer.parseInt(System.console().readLine("Enter the salary :"));
compute(s);
}
catch(MyException e)
{
System.out.println("caugth;"+e);
}
}
}
No comments:
Post a Comment