class personException extends Exception
{
}
class Demo
{
public int show(int x,int y) throws personException
{
if(y<0)
throw new personException();
return x/y;
}
}
class exceptionDemo
{
public static void main(String[] args)
{
Demo d=new Demo();
try
{
int z=d.show(4,-1);
System.out.println(z);
}
catch (personException e)
{
System.out.println("负数出现了");
}
System.out.println("over");
}
}
|
|