Initial commit

This commit is contained in:
2025-11-06 10:29:13 +08:00
commit 0becd14830
318 changed files with 7145 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
package ch07;
import java.io.IOException;
import java.util.Scanner;
public class throwsDemo {
public static void test() throws NullPointerException, IOException {
System.out.println("请输入一个数字01");
Scanner in = new Scanner(System.in);
int flag = in.nextInt();
if (flag == 1)
throw new NullPointerException();
else
throw new IOException();
}
public static void main(String[] args) {
try {
test();
} catch (NullPointerException e) {
System.out.println("系统抛出了" + e.getClass() + "类型的异常");
} catch (IOException e) {
System.out.println("系统抛出了" + e.getClass() + "类型的异常");
}
}
}