【发布时间】:2015-06-25 22:27:21
【问题描述】:
为什么需要在java中检查FileInputStream中的ArrayIndexOutOfBounds?在一本关于核心 java 的书中给出了相同的代码作为示例。
FileInputStream fis;
try{
//fis=new FileInputStream("inputFIle.txt");
fis=new FileInputStream(argv[0]);
}catch(FileNotFoundException e){
System.out.println("File was not found");
}catch(ArrayIndexOutOfBoundsException e){
e.printStackTrace();
}
【问题讨论】:
-
不能。据我所知,这只是一个非常糟糕的例子——假设你已经准确地复制了它。
-
也许原代码中的try块包含其他可能抛出ArrayIndexOutOfBoundsException的方法调用。您发布的代码没有通过编译。
-
@Eran 是的。这是一个未经检查的异常。
-
@user2025949 请提供正确的引文:作者、标题、版本、章节和页码。
-
@EJP 关于
ArrayIndexOutOfBoundsException未被选中是正确的。但是,发布的代码包含ArrayIndexOutOfBounds。我不知道那是什么:)
标签: java exception-handling io inputstream indexoutofboundsexception