【发布时间】:2013-12-06 05:28:14
【问题描述】:
我对 Java 比较陌生,而且我总是遇到代码中的 Try/Catch 函数的问题,所以我想知道你们是否可以帮助我。
我遇到的问题是我编写了一个 try/catch,但我收到一条错误消息,指出永远不会抛出异常。我在我的整体代码的另一部分写了一个类似的语句,它运行良好,所以我想知道这个问题是什么。
代码如下:
public String getMatchedLogs(String matchStr, File logFile) {
String fileLine = "";
try {
Scanner ipScan = new Scanner(fileLine);
if (fileLine.indexOf(matchStr) > -1) {
output += fileLine;
}else{
System.out.println(fileLine.indexOf(""));
}
} catch (FileNotFoundException fnfe) {
System.out.println(fnfe.getMessage());
}
return fileLine;
} //end getMatchedLogs
错误出现在 catch 中,它表示永远不会抛出异常。所以如果你们能给我一些关于发生了什么的见解,我将不胜感激。
【问题讨论】:
-
为什么要扫描空字符串并获取未使用的参数?
标签: java error-handling