《Java程序设计》(五)异常处理-知识点训练卷 2026版吉林省高职分类考试《信息工程类(电子与信息类)考纲百套卷》第35卷

2025-09-07
| 2份
| 26页
| 81人阅读
| 0人下载

内容正文:

编写说明:2026版吉林省高职分类考试《信息工程类(电子与信息类)考纲百套卷》,依据吉林省高职分类(对口招生)考试各类专业综合卷考试科目及纲要(2021版),种信息工程类(电子与信息类)专业综合卷考试科目及纲要编写。本专辑共150份试卷两部分组成,第一部分是按考纲的考点要求编写的120份知识点训练卷,第二部分是针对6门课程的掌握要求,编写的30份常考题训练卷。 本试卷是吉林省高职分类考试《信息工程类(电子与信息类)考纲百套卷》的第35卷,是知识点训练卷。按“Java程序设计”考试纲要(五)异常处理的三点知识点要求编写,其三点要求是: 1.了解异常的概念,理解异常处理机制。 2.掌握用try-catch-finally语句捕获异常。 3.掌握throw语句、throws子句和声明抛出异常。。 2026版吉林省《信息工程类(电子与信息类)考纲百套卷》 第35卷 《Java程序设计》 (五)异常处理-知识点训练卷 考试时间60分钟 满分100分 班级 姓名 学号 成绩 一、选择题(本大题共10小题,每小题2分,共20分) 1. 在 Java 中,以下是所有异常类的父类的是( ) A. Error B. RuntimeException C. Throwable D. Exception 答案:D 2. 以下代码执行后的输出结果是()。 public class Test { public static void main(String[] args) { try { System.out.print("A"); int num = 5 / 0; System.out.print("B"); } catch (ArithmeticException e) { System.out.print("C"); } finally { System.out.print("D"); } System.out.print("E"); } } A. ACDE B. ACD C. ABCE D. AE 答案:A 3. 关于throw和throws关键字,以下说法错误的是()。 A. throw用于在方法体内抛出异常对象 B. throws用于方法声明,指明该方法可能抛出的异常类型 C. throws可以抛出多个异常类型,用逗号分隔 D. throw只能抛出Exception类的子类对象 答案:D 4. 当一个方法可能会抛出多种异常时,在方法声明中应该使用( )关键字来声明这些异常 A. try B. catch C. finally D. throws 答案:D 5.以下关于 try-catch-finally 语句块中 finally 块的说法,正确的是( ) A. 若 try 块中没有异常抛出,finally 块不会执行 B. 若 try 块中有 return 语句,finally 块不会执行 C. 无论 try 块中是否抛出异常,finally 块都会执行 D. 只有 catch 块捕获到异常时,finally 块才会执行 答案:C 6.以下代码执行后的输出结果是()。 public class Test { public static void main(String[] args) { try { System.out.print("A"); throw new RuntimeException("B"); } catch (RuntimeException e) { System.out.print(e.getMessage()); } catch (Exception e) { System.out.print("C"); } finally { System.out.print("D"); } } } A. ABD B. ABCD C. ACD D. AC 答案:A 7.有如下代码片段: try { int a = 1 / 0; } catch (ArithmeticException e) { throw new RuntimeException("计算错误", e); } 这里的 throw 语句作用是( ) A. 捕获 ArithmeticException 异常 B. 声明方法可能抛出 RuntimeException 异常 C. 创建并抛出一个新的 RuntimeException 异常,且将原异常作为其原因 D. 捕获并处理 RuntimeException 异常 答案:C 8.以下代码中,try-catch 块的使用正确的是( ) A. try { int[] arr = new int[5]; arr[10] = 1; } catch (ArrayIndexOutOfBoundsException e) { System.out.println("数组越界异常"); } B. try { int[] arr = new int[5]; arr[10] = 1; } catch (NullPointerException e) { System.out.println("空指针异常"); } C. try { int a = 1 / 0; } catch (IOException e) { System.out.println("输入输出异常"); } D. try { String str = null; str.length(); } catch (ArrayIndexOutOfBoundsException e) { System.out.println("数组越界异常"); } 答案:A 9.若一个方法声明为 public void method() throws IOException, SQLException,以下说法正确的是( ) A. 该方法只能抛出 IOException 和 SQLException 异常 B. 该方法可以抛出 IOException 和 SQLException 及其子类异常 C. 调用该方法时,不需要处理这两种异常 D. 该方法内部不能抛出其他类型的异常 答案:B 10.以下代码的输出结果是( ) public class Test { public static void main(String[] args) { try { System.out.print("A"); throw new RuntimeException(); } catch (Exception e) { System.out.print("B"); return; } finally { System.out.print("C"); } } } A. AB B. ABC C. AC D. BC 答案:B 二、判断题(本大题共10小题,每小题2分,共20分) 1. finally块中的代码只有在try块中没有异常时才会执行。( ) 答案:错误 2. 自定义异常类通常通过继承Exception或其子类来实现。( ) 答案:正确 3. 在catch块中捕获异常时,应先捕获父类异常,再捕获子类异常。( ) 答案:错误 4. 如果一个方法没有声明抛出任何异常,那么它内部就不会抛出任何异常。( ) 答案:错误 5.try 块中可以没有 catch 块,但必须有 finally 块。( ) 答案:错误 6.对于受检异常,如果不使用try-catch捕获,就必须在方法声明中使用throws抛出。( ) 答案:正确 7.throw 语句抛出的异常对象可以是任何 Throwable 类的子类对象。( ) 答案:正确 8.如果 try 块中抛出的异常没有被任何 catch 块捕获,程序会立即终止。( ) 答案:错误 9.finally 块中的代码在任何情况下都会执行。( ) 答案:错误 10.Error和Exception都继承自Throwable类,因此都应该在程序中显式捕获处理。( ) 答案:错误 三、填空题(本大题共5小题,每题2分,共10分) 1. 在 Java 中,用于捕获异常的关键字是 __________。 答案:catch 2. 如果一个方法可能抛出多个受检查异常,在方法声明中使用 __________ 关键字声明这些异常时,异常之间用分隔。 答案:throws 3.在 Java 中,若要自定义一个受检查异常类,通常需要继承 __________ 类。 答案:Exception 4.在 Java 的异常体系中,RuntimeException 类是 __________ 类的子类。 答案:Exception 5.在 Java 异常体系中,所有的异常和错误的基类是 __________。 答案:Throwable 四、读程序写结果题(本大题共5小题,每题5分,共25分) 1.以下程序的运行结果是______。 public class Test1 { public static void main(String[] args) { try { int[] arr = new int[1]; arr[1] = 10; // 注意索引越界 } catch (ArrayIndexOutOfBoundsException e) { System.out.print("A"); } catch (Exception e) { System.out.print("B"); } finally { System.out.print("C"); } System.out.print("D"); } } 答案:ACD 2.以下程序的运行结果是______。 public class Test2 { public static void main(String[] args) { try { System.out.print("A"); throw new IOException("B"); } catch (IOException e) { System.out.print("C"); } catch (Exception e) { System.out.print("D"); } finally { System.out.print("E"); } } } 答案:ACE 3.以下程序的运行结果是______。 public class Test3 { public static void main(String[] args) { try { System.out.print("A"); return; } catch (Exception e) { System.out.print("B"); } finally { System.out.print("C"); } System.out.print("D"); } } 答案:AC 4.以下程序的运行结果是______。 public class Test5 { public static void main(String[] args) { try { method(); System.out.print("A"); } catch (RuntimeException e) { System.out.print("B"); } } public static void method() { throw new RuntimeException("C"); } } 答案:B 5.以下程序的运行结果是______。 public class ExceptionTest5 { public static void main(String[] args) { try { System.out.println("try 块开始"); throw new Exception("自定义异常信息"); } catch (Exception e) { System.out.println("捕获到异常:" + e.getMessage()); try { System.out.println("内层 try 块开始"); throw new RuntimeException("运行时异常信息"); } catch (RuntimeException re) { System.out.println("捕获到运行时异常:" + re.getMessage()); throw re; } finally { System.out.println("内层 finally 块执行"); } } finally { System.out.println("外层 finally 块执行"); } } } 答案: try 块开始 捕获到异常:自定义异常信息 内层 try 块开始 捕获到运行时异常:运行时异常信息 内层 finally 块执行 外层 finally 块执行 Exception in thread "main" java.lang.RuntimeException: 运行时异常信息 at ExceptionTest5.main(ExceptionTest5.java:10) 五、编程题(本大题共5小题,每题5分,共25分) 1.编写一个程序,让用户输入两个整数,计算它们的商并输出结果。如果用户输入的除数为零,捕获 ArithmeticException 异常并输出错误信息。 答案: import java.util.Scanner; public class DivideProgram { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); try { System.out.print("请输入被除数:"); int dividend = scanner.nextInt(); System.out.print("请输入除数:"); int divisor = scanner.nextInt(); int result = dividend / divisor; System.out.println("商为:" + result); } catch (ArithmeticException e) { System.out.println("错误:除数不能为零"); } scanner.close(); } } 2.编写一个程序,定义一个方法 getElement,该方法接受一个整数数组和一个索引作为参数,返回数组中指定索引的元素。如果索引越界,捕获 ArrayIndexOutOfBoundsException 异常并输出错误信息。 答案: public class ArrayElementProgram { public static int getElement(int[] arr, int index) { try { return arr[index]; } catch (ArrayIndexOutOfBoundsException e) { System.out.println("错误:索引越界"); return -1; } } public static void main(String[] args) { int[] arr = {1, 2, 3, 4, 5}; int index = 10; int element = getElement(arr, index); if (element != -1) { System.out.println("数组中索引为 " + index + " 的元素是:" + element); } } } 3.编写一个程序,定义一个自定义异常类 AgeException,表示年龄不合法。创建一个 Person 类,包含 name 和 age 属性,在设置年龄时,如果年龄小于 0 或大于 150,抛出AgeException 异常。 答案: // 自定义异常类 class AgeException extends Exception { public AgeException(String message) { super(message); } } // Person 类 class Person { private String name; private int age; public Person(String name, int age) throws AgeException { this.name = name; setAge(age); } public void setAge(int age) throws AgeException { if (age < 0 || age > 150) { throw new AgeException("年龄不合法:年龄必须在 0 到 150 之间"); } this.age = age; } public int getAge() { return age; } public String getName() { return name; } } // 主类 public class CustomExceptionProgram { public static void main(String[] args) { try { Person person = new Person("张三", 200); System.out.println(person.getName() + " 的年龄是:" + person.getAge()); } catch (AgeException e) { System.out.println(e.getMessage()); } } } 4.编写一个程序,模拟文件读取操作。定义一个方法 readFile,该方法声明抛出 FileNotFoundException 异常。在 main 方法中调用 readFile 方法,使用 try-catch 块捕获并处理该异常。 答案: import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class FileReadProgram { public static void readFile(String filePath) throws FileNotFoundException { File file = new File(filePath); Scanner scanner = new Scanner(file); while (scanner.hasNextLine()) { System.out.println(scanner.nextLine()); } scanner.close(); } public static void main(String[] args) { String filePath = "nonexistent.txt"; try { readFile(filePath); } catch (FileNotFoundException e) { System.out.println("错误:文件未找到 - " + e.getMessage()); } } } 5.编写一个程序,定义一个方法 processData,该方法接受一个整数数组作为参数。在 processData 方法中,遍历数组,如果数组元素为负数,抛出一个自定义异常 NegativeNumberException。在 main 方法中调用 processData 方法,使用 try-catch 块捕获并处理该异常,同时在 finally 块中输出 “处理完成”。 答案: // 自定义异常类 class NegativeNumberException extends Exception { public NegativeNumberException(String message) { super(message); } } public class DataProcessingProgram { public static void processData(int[] arr) throws NegativeNumberException { for (int num : arr) { if (num < 0) { throw new NegativeNumberException("数组中包含负数:" + num); } } System.out.println("数组处理成功"); } public static void main(String[] args) { int[] arr = {1, 2, -3, 4, 5}; try { processData(arr); } catch (NegativeNumberException e) { System.out.println(e.getMessage()); } finally { System.out.println("处理完成"); } } } 原创精品资源学科网独家享有版权,侵权必究! 学科网(北京)股份有限公司 学科网(北京)股份有限公司 学科网(北京)股份有限公司 $$ 编写说明:2026版吉林省高职分类考试《信息工程类(电子与信息类)考纲百套卷》,依据吉林省高职分类(对口招生)考试各类专业综合卷考试科目及纲要(2021版),种信息工程类(电子与信息类)专业综合卷考试科目及纲要编写。本专辑共150份试卷两部分组成,第一部分是按考纲的考点要求编写的120份知识点训练卷,第二部分是针对6门课程的掌握要求,编写的30份常考题训练卷。 本试卷是吉林省高职分类考试《信息工程类(电子与信息类)考纲百套卷》的第35卷,是知识点训练卷。按“Java程序设计”考试纲要(五)异常处理的三点知识点要求编写,其三点要求是: 1.了解异常的概念,理解异常处理机制。 2.掌握用try-catch-finally语句捕获异常。 3.掌握throw语句、throws子句和声明抛出异常。。 2026版吉林省《信息工程类(电子与信息类)考纲百套卷》 第35卷 《Java程序设计》 (五)异常处理-知识点训练卷 考试时间60分钟 满分100分 班级 姓名 学号 成绩 一、选择题(本大题共10小题,每小题2分,共20分) 1. 在 Java 中,以下是所有异常类的父类的是( ) A. Error B. RuntimeException C. Throwable D. Exception 2. 以下代码执行后的输出结果是()。 public class Test { public static void main(String[] args) { try { System.out.print("A"); int num = 5 / 0; System.out.print("B"); } catch (ArithmeticException e) { System.out.print("C"); } finally { System.out.print("D"); } System.out.print("E"); } } A. ACDE B. ACD C. ABCE D. AE 3. 关于throw和throws关键字,以下说法错误的是()。 A. throw用于在方法体内抛出异常对象 B. throws用于方法声明,指明该方法可能抛出的异常类型 C. throws可以抛出多个异常类型,用逗号分隔 D. throw只能抛出Exception类的子类对象 4. 当一个方法可能会抛出多种异常时,在方法声明中应该使用( )关键字来声明这些异常 A. try B. catch C. finally D. throws 5.以下关于 try-catch-finally 语句块中 finally 块的说法,正确的是( ) A. 若 try 块中没有异常抛出,finally 块不会执行 B. 若 try 块中有 return 语句,finally 块不会执行 C. 无论 try 块中是否抛出异常,finally 块都会执行 D. 只有 catch 块捕获到异常时,finally 块才会执行 6.以下代码执行后的输出结果是()。 public class Test { public static void main(String[] args) { try { System.out.print("A"); throw new RuntimeException("B"); } catch (RuntimeException e) { System.out.print(e.getMessage()); } catch (Exception e) { System.out.print("C"); } finally { System.out.print("D"); } } } A. ABD B. ABCD C. ACD D. AC 7.有如下代码片段: try { int a = 1 / 0; } catch (ArithmeticException e) { throw new RuntimeException("计算错误", e); } 这里的 throw 语句作用是( ) A. 捕获 ArithmeticException 异常 B. 声明方法可能抛出 RuntimeException 异常 C. 创建并抛出一个新的 RuntimeException 异常,且将原异常作为其原因 D. 捕获并处理 RuntimeException 异常 8.以下代码中,try-catch 块的使用正确的是( ) A. try { int[] arr = new int[5]; arr[10] = 1; } catch (ArrayIndexOutOfBoundsException e) { System.out.println("数组越界异常"); } B. try { int[] arr = new int[5]; arr[10] = 1; } catch (NullPointerException e) { System.out.println("空指针异常"); } C. try { int a = 1 / 0; } catch (IOException e) { System.out.println("输入输出异常"); } D. try { String str = null; str.length(); } catch (ArrayIndexOutOfBoundsException e) { System.out.println("数组越界异常"); } 9.若一个方法声明为 public void method() throws IOException, SQLException,以下说法正确的是( ) A. 该方法只能抛出 IOException 和 SQLException 异常 B. 该方法可以抛出 IOException 和 SQLException 及其子类异常 C. 调用该方法时,不需要处理这两种异常 D. 该方法内部不能抛出其他类型的异常 10.以下代码的输出结果是( ) public class Test { public static void main(String[] args) { try { System.out.print("A"); throw new RuntimeException(); } catch (Exception e) { System.out.print("B"); return; } finally { System.out.print("C"); } } } A. AB B. ABC C. AC D. BC 二、判断题(本大题共10小题,每小题2分,共20分) 1. finally块中的代码只有在try块中没有异常时才会执行。( ) 2. 自定义异常类通常通过继承Exception或其子类来实现。( ) 3. 在catch块中捕获异常时,应先捕获父类异常,再捕获子类异常。( ) 4. 如果一个方法没有声明抛出任何异常,那么它内部就不会抛出任何异常。( ) 5.try 块中可以没有 catch 块,但必须有 finally 块。( ) 6.对于受检异常,如果不使用try-catch捕获,就必须在方法声明中使用throws抛出。( ) 7.throw 语句抛出的异常对象可以是任何 Throwable 类的子类对象。( ) 8.如果 try 块中抛出的异常没有被任何 catch 块捕获,程序会立即终止。( ) 9.finally 块中的代码在任何情况下都会执行。( ) 10.Error和Exception都继承自Throwable类,因此都应该在程序中显式捕获处理。( ) 三、填空题(本大题共5小题,每题2分,共10分) 1. 在 Java 中,用于捕获异常的关键字是 __________。 2. 如果一个方法可能抛出多个受检查异常,在方法声明中使用 __________ 关键字声明这些异常时,异常之间用分隔。 3.在 Java 中,若要自定义一个受检查异常类,通常需要继承 __________ 类。 4.在 Java 的异常体系中,RuntimeException 类是 __________ 类的子类。 5.在 Java 异常体系中,所有的异常和错误的基类是 __________。 四、读程序写结果题(本大题共5小题,每题5分,共25分) 1.以下程序的运行结果是______。 public class Test1 { public static void main(String[] args) { try { int[] arr = new int[1]; arr[1] = 10; // 注意索引越界 } catch (ArrayIndexOutOfBoundsException e) { System.out.print("A"); } catch (Exception e) { System.out.print("B"); } finally { System.out.print("C"); } System.out.print("D"); } } 2.以下程序的运行结果是______。 public class Test2 { public static void main(String[] args) { try { System.out.print("A"); throw new IOException("B"); } catch (IOException e) { System.out.print("C"); } catch (Exception e) { System.out.print("D"); } finally { System.out.print("E"); } } } 3.以下程序的运行结果是______。 public class Test3 { public static void main(String[] args) { try { System.out.print("A"); return; } catch (Exception e) { System.out.print("B"); } finally { System.out.print("C"); } System.out.print("D"); } } 4.以下程序的运行结果是______。 public class Test5 { public static void main(String[] args) { try { method(); System.out.print("A"); } catch (RuntimeException e) { System.out.print("B"); } } public static void method() { throw new RuntimeException("C"); } } 5.以下程序的运行结果是______。 public class ExceptionTest5 { public static void main(String[] args) { try { System.out.println("try 块开始"); throw new Exception("自定义异常信息"); } catch (Exception e) { System.out.println("捕获到异常:" + e.getMessage()); try { System.out.println("内层 try 块开始"); throw new RuntimeException("运行时异常信息"); } catch (RuntimeException re) { System.out.println("捕获到运行时异常:" + re.getMessage()); throw re; } finally { System.out.println("内层 finally 块执行"); } } finally { System.out.println("外层 finally 块执行"); } } } 五、编程题(本大题共5小题,每题5分,共25分) 1.编写一个程序,让用户输入两个整数,计算它们的商并输出结果。如果用户输入的除数为零,捕获 ArithmeticException 异常并输出错误信息。 2.编写一个程序,定义一个方法 getElement,该方法接受一个整数数组和一个索引作为参数,返回数组中指定索引的元素。如果索引越界,捕获 ArrayIndexOutOfBoundsException 异常并输出错误信息。 3.编写一个程序,定义一个自定义异常类 AgeException,表示年龄不合法。创建一个 Person 类,包含 name 和 age 属性,在设置年龄时,如果年龄小于 0 或大于 150,抛出AgeException 异常。 4.编写一个程序,模拟文件读取操作。定义一个方法 readFile,该方法声明抛出 FileNotFoundException 异常。在 main 方法中调用 readFile 方法,使用 try-catch 块捕获并处理该异常。 5.编写一个程序,定义一个方法 processData,该方法接受一个整数数组作为参数。在 processData 方法中,遍历数组,如果数组元素为负数,抛出一个自定义异常 NegativeNumberException。在 main 方法中调用 processData 方法,使用 try-catch 块捕获并处理该异常,同时在 finally 块中输出 “处理完成”。 原创精品资源学科网独家享有版权,侵权必究! 学科网(北京)股份有限公司 学科网(北京)股份有限公司 学科网(北京)股份有限公司 $$

资源预览图

《Java程序设计》(五)异常处理-知识点训练卷 2026版吉林省高职分类考试《信息工程类(电子与信息类)考纲百套卷》第35卷
1
《Java程序设计》(五)异常处理-知识点训练卷 2026版吉林省高职分类考试《信息工程类(电子与信息类)考纲百套卷》第35卷
2
《Java程序设计》(五)异常处理-知识点训练卷 2026版吉林省高职分类考试《信息工程类(电子与信息类)考纲百套卷》第35卷
3
所属专辑
由于学科网是一个信息分享及获取的平台,不确保部分用户上传资料的 来源及知识产权归属。如您发现相关资料侵犯您的合法权益,请联系学科网,我们核实后将及时进行处理。