异常的抛出

 

div的异常抛给main来处理:

class Math{
    public int div(int i,int j)throws Exception{
        int temp=i/j;
        return temp;
    }
}
public class ThrowsDemo01 {
public static void main(String[] args){
    Math m=new Math();
        try {
            System.out.println("Divation opration: "+m.div(10, 0));
        } catch (Exception e) {
            e.printStackTrace();
        }
}
}

posted @ 2014-08-05 09:46  塔斯曼  阅读(130)  评论(0编辑  收藏  举报