class FuShuException1 extends RuntimeException
{
FuShuException1(String msg)
{
super(msg);
}
}
class Demo3
{
int div(int a,int b) throws ArithmeticException
{
if(b<0)
throw new FuShuException1("出现除数为负数了");
if(b==0)
throw new ArithmeticException("被零除了");
return a/b;
}
}
public class ExceptionDemo3 {
public static void main(String[] args) //throws Exception
{
Demo3 d=new Demo3();
int x=d.div(3, -9);
//此处抛出 new AritchmeticException()
System.out.println("x="+x);
System.out.println("This over!");
}
}
/*
class Person
{
public void checkName(String name)
{
//if(name.equals("萝莉")) //NullPointerException
if("萝莉".equals(name)) //if(name!=null&&name.equals("萝莉"))
System.out.println("Yes");
else
System.out.println("No");
}
}
main()
{
Person p=new Person();
p.checkName(null);
}