这个问题我也很疑惑,所以自己写了test来给自己解惑下
try catch在for循环外面,并且,catch 只答应日志,不抛出异常
public static void main(String[] args) {
try {
for (int i = 0; i < 10; i++) {
System.out.println(i);
int i1 = 1;
System.out.println(i1 / i);
}
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("是否继续");
}
java.lang.ArithmeticException: / by zero
0
at com.linewell.zhzf.api.gateway.gateway.Test.main(Test.java:14)
是否继续Process finished with exit code 0
try catch在for 循环外面就直接抛出异常,就不继续执行for循环里的业务了,继续走for循环外面的业务。
public static void main(S