java – 编译器如何知道在执行之前要抛出的异常?
发布时间:2020-12-15 02:05:31 所属栏目:Java 来源:网络整理
导读:import java.io.*;class ex3{ public static void main(String args[]) { myfun(); } static void myfun() { try { FileInputStream f = new FileInputStream("file.ytxt"); System.out.println("my fun"); } catch(Exception e) //Line 1 { System.out.prin
import java.io.*; class ex3 { public static void main(String args[]) { myfun(); } static void myfun() { try { FileInputStream f = new FileInputStream("file.ytxt"); System.out.println("my fun"); } catch(Exception e) //Line 1 { System.out.println(e.getMessage()); } catch(FileNotFoundException e) //Line 2 { System.out.println("File Not Found Caught"); } } } 我创建了两个异常处理程序代码(一个是通用的,另一个是第1行和第2行). 我的编译器在抱怨 ex3.java:24: error: exception FileNotFoundException has already been caught catch(FileNotFoundException e) ^ 1 error 我的问题是编译器是如何知道try块会抛出“FileNotFoundException”的? 解决方法
catch(FileNotFoundException e)此行无法访问.以来:
FileNotFoundException扩展了Exception 见Exception和FileNotFoundException: 您可能想要切换订单. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |