java代码模型6(异常处理格式)

来源:互联网 发布:http网络协议 编辑:程序博客网 时间:2024/06/06 02:51
package a1;class Mymath{    public static int div(int x,int y) throws Exception{    int result=0;    System.out.println("1.计算开始");    try{    result=x/y;    }catch(Exception e){            throw e;    }    finally{    System.out.println("2.计算结束");    }    return result;    }}public class Test{    public static void main(String args[]){        try{        System.out.println(Mymath.div(8, 0));        }catch(Exception e){            e.printStackTrace();        }    }}

结果如下:
这里写图片描述

0 0