我的客戶端代碼:未報告的異常java.io FileNotFoundException;必須捕獲或聲明拋出
public static void inputFiles()
{
File inputFile = new File("colors2.txt");
if (!inputFile.exists()) {
throw new FileNotFoundException(("File not found"));
}
ColorSet colorSetter = new ColorSet(inputFile);
}
我的供應商類的構造函數:
public ColorSet(File source) throws FileNotFoundException
{
if (!source.exists()) {
throw new FileNotFoundException(("File not found"));
}
colorInput = source;
}
我不斷獲取 「沒有報告異常java.io FileNotFoundException異常;必須捕獲或聲明拋出「
我試着在客戶端方法中捕獲它,但它告訴我它不能在body block中調用,也許我做錯了嗎?
所以對於我的客戶端方法,它應該是:public static void inputFile()throws FileNotFoundException? – pood 2012-02-17 18:26:07
是的,這就是它需要做的 – 2012-02-17 18:35:10