cry catch 基本用法

来源:互联网 发布:seo外链在线群发 编辑:程序博客网 时间:2024/06/07 09:36
class DivisorIsZeroException  extends Exception{
public DivisorIsZeroException(String errorMessage){
super(errorMessage);
}
}
class A{
int divide(int a,int b){
try{
if(0==b)
throw new DivisorIsZeroException("hahaha");
}
catch(DivisorIsZeroException e){
e.printStackTrace();
}
int m=a/b;
return m;
}

}
public class TestA{
public static void main(String[] args){
A aa=new A();
int W=aa.divide(6,0);
System.out.printf("%d\n",W);
}
}
原创粉丝点击