面试题: 模拟虚拟机处理异常的方式
JVM处理异常的方式:
1.打印错误信息
- a.异常的类名
- b.异常信息
- c.异常的位置
- d.错误的行号
2.将程序停止
public class ExceptionDemo04 {
public static void main(String[] args) throws IOException {
System.out.println("Start");
int a = 10;
int b = 0;
try {
System.out.println(a /b);
} catch (Exception e) {
e.printStackTrace();
// 程序结束
System.exit(0);
}
System.out.println("End");
}
}