- class FuShuException extends Exception
- {
- private int value;
- FuShuException()
- {
- super();
- }
- FuShuException(String msg,int value)
- {
- super (msg);
- this.value=value;
- }
- public int getValue()
- {
- return value;
- }
- }
- class Demo
- {
- int div(int a,int b)throws FuShuException
- {
- if(b<0)
- throw new FuShuException("出现了负数",b);
- return a/b;
- }
- }
- class ExceptionDemo3
- {
- public static void main(String[] args)throws FuShuException
- {
- Demo d=new Demo();
-
- try
- {
- int x=d.div(4,-1);
- System.out.println("x="+x);
- }
- catch (Exception e)
- {
-
- System.out.println(e.toString()+e.getValue());
- //System.out.println(e.toString());
- //e.printStackTrace();
- }
- System.out.println("over");
- }
- }
复制代码 无法编译通过的 大家猜猜是哪里 :lol |
|