//使用throws,并设置异常处理ArithmeticException
class Ex4_2_1
{
public static void main(String[] args)
{
//1.当所辖程序块发生ArithmeticException的内置错误时,
//将按照异常处理ArithmeticException的规则处理
throws ArithmeticException
{
int x,y;
//2.分母为0,系统将以异常处理ArithmeticException进行处理,
//并输出相关内容
y=0;
x=10/y;
System.out.println("x="+x);
}
}
}
40.throws的用法
最新推荐文章于 2023-08-07 09:15:43 发布