User Defined Exception In Java
/*
Contributed by Anonymous :: Blog is not responsible for any copyright claims
*/
import java.util.Scanner;
class Xception extends Exception
{
int detail;
Xception(int a)
{
detail = a;
}
public String toString()
{
return "Xception [ " + detail + "]";
}
}
class Xceptiondemo
{
static void compute(int a) throws Xception
{
System.out.println("called compute ("+a+")");
if(a>10)
throw new Xception(a);
System.out.println("Normal exit");
}
public static void main(String [] args)
{
try
{
compute(1);
compute(20);
}
catch(Xception e)
{
System.out.println("Caught"+e);
}
}
}
1 comment:
i didn't understood the use of java.util.Scanner in this particular program ?
Post a Comment