第八天
package exception;
public class Test000 {
public static void main(String[] args) {
hhh(100);//方法内已经使用try,catch抛出捕获异常。直接使用方法就行。
}
static void hhh(int a){ //方法内用catch捕获异常,不用继续往上抛出
try {
if (a > 10) {
throw new Exception();
}
System.out.println("ok");
} catch (Exception e) {
System.out.println("这是一个异常");
}
}
}
浙公网安备 33010602011771号