本帖最后由 王宝龙 于 2012-9-23 22:14 编辑
- class FuShuException extends Exception
- {
-
- }
- class ExceptionA
- {
- private double result;
- public void div(int a,int b)throws FuShuException
- {
- if(b==0)
- {
- throw new FuShuException();
- }
- result = a/b;
- }
- public double getResult()
- {
- return result;
- }
- }
- class ExceptionDemo
- {
- public static void main(String [] arge)
- {
- ExceptionA a = new ExceptionA();
-
- System.out.println("fun()返回值:"+fun(a));
- System.out.println("over");
- }
- public static int fun(ExceptionA a)
- {
- try
- {
- a.div(4,0);//<font color="red">这里如果是(4,1)返回值仍然是2!!!!!不解!!!</font>
- System.out.println(a.getResult());
- return 1;
- }
- catch(FuShuException e)
- {
- System.out.println(e.getMessage());
- System.out.println(e);
- }
- finally
- {
- return 2;
- }
- }
- }
复制代码 如果这样a.div(4,0)返回值为2。可是这样a.div(4,1)的话返回值还是2为什么不是1呢?这是为什么?谢谢各位帮忙看一下!! |