throws exception

class exe18 extends Exception
{
private int detail;
exe18()
{
System.out.println("default");
}

exe18(int detail)
{
this.detail=detail;
}

public String toString()
{
return"myexception["+detail+"]";
}


static void compute(int detail) throws exe18
{
System.out.println("called compute("+detail+")");
if(detail>10)
throw new exe18(detail);
System.out.println("normal exit");
}
}
class exe19
{
public static void main(String args[])
{

try
{
exe18.compute(8);
exe18.compute(54);
}
catch(exe18 e)
{
System.out.println("caught "+e);
System.out.println(e.toString());
}
}
}

No comments:

Post a Comment

Template Design by faris vio