java | own Exception
//Example of my own Exception
class MyException extends Exception
{
int no;
MyException(int val)
{
no=val;
}
public String toString()
{
return "Myexception a<"+no+".";
}
}
class Test
{
static void compute(int a)throws MyException
{
if(a<10)
throw new MyException(a);
System.out.println("this is ok a>=10");
}
public static void main(String ar[])
{
try{
compute(1);
compute(10);
}
catch(MyException e)
{
System.out.println("Exception caught"+e);
}
}
}
0 comments:
Post a Comment