其他分享
首页 > 其他分享> > 异常exception

异常exception

作者:互联网

 

public class Test01 {
public static void main(String[] args) {
new Test01().device(1,0);
}
public int device(int a,int b) throws ArithmeticException {//throws用在参数后面
if (b==0){
throw new ArithmeticException();//throw用在方法体中
}
System.out.println("有异常");
return a/b;

}
}
/* int a=1,b=0;
try { //try是监控区域,监控方法体中的代码是否有异常
System.out.println(a/b);
} catch (ArithmeticException e){//catch根据异常的类型是捕获异常
System.out.println("ArithmeticException");
}
finally {//用于收尾阶段
System.out.println("异常已捕获");
}*/

 

标签:exception,int,ArithmeticException,System,println,异常,out
来源: https://www.cnblogs.com/linhengBoKe/p/15777379.html