我对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中,它表示永远不会抛出异常.所以,如果你们能给我一些有关正在发生的事情的见解,我会非常感激.