| 本帖最后由 曾振华 于 2013-10-12 18:45 编辑 
 class FuShuException extends Exception
 {
 private int value;
 //private String msg;
 FuShuException(String msg)
 {
 //this.msg = msg;
 super(msg);
 this.value = value;
 }
 public int getValue()
 {
 return value;
 }
 //public String getMessage()
 //{
 //return msg;
 //}
 }
 
 class Demo
 {
 int div (int a ,int b)throws FuShuException
 {
 if(b<0)
 throw new FuShuException("除数出现了负数-- /bu fushu",b);
 return  a/b;
 }
 }
 
 
 class  ExceptionDemo
 {
 public static void main(String[] args)
 {
 Demo de = new Demo();
 try
 {
 int x = de.div(4,-2);
 System.out.println("x="+x);
 }
 catch (FuShuException e)
 {
 System.out.println(e.toString());
 //System.out.println("出现负数了");
 System.out.println("错误的负数是"+e.getValue());
 }
 System.out.println("over");
 }
 }
 
 自定义一个当除数为负数就是异常的程序,编译时出现了异常- -
 
 
   
 这是什么情况啊?
 
 
 |