






























简易预习流程:先看预习课件,认真完成里面的习题与调查。然后试着在电脑前完成课前问题列表中的3-5。注意:可根据需要观看线上课程视频。
说出两个我们在使用软件、APP时遇到的异常。这些异常可能是什么类型的异常?你是怎么解决这类异常呢(重启、查看日志...)?
说出两个你在编写Java程序时最常遇到的异常。并判定这些异常是什么类型的问题(编译期问题、运行时问题)。你认为哪种类型的问题更好解决呢?
查询JDK文档,说说如下代码哪行抛出了什么类型的异常?为什么该段程序在运行时可能产生问题,但是不写try...catch,也可编译通过。
public static void main(String[] args) {
int[] x = new int[3];
Scanner inputScan = new Scanner(System.in);
for(int i = 0; i < x.length;){
System.out.println("Please input the "+i+" integer:");
String inputInt = inputScan.nextLine();
x[i] = Integer.parseInt(inputInt); // 注意这里!
i++;
}
System.out.println(Arrays.toString(x));
}
尝试为上述代码添加try...catch。使得当输入错误时,可提示重新输入,直到输入正确后,才能继续往下执行。
String x = "abc";
try {
int a = Integer.parseInt(x);
System.out.println(a);
} catch (NumberFormatException e) {
e.printStackTrace();
}
String fileName = "abc";
FileReader fileReader = new FileReader(fileName);
可演示如下两部分内容之一:
请在周四课前联系老师要求展示。
完成题集Java-07-异常处理中的:
课外阅读:AI大模型相关资料,掌握使用良好的Prompt生成高质量内容。
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。