對於我在Java中的最終測試,我們在測試中使用try,catch和finally調用了一個「exceptions」部分。當我嘗試將示例代碼放入Eclipse中時,我會在catch中發現錯誤並拋出新的區域。所有錯誤都會顯示「無法解析輸入」。IOException無法解析爲類型錯誤
我該如何解決這個問題,以便我可以學習/檢查代碼應該做什麼?
Q4類
public static void main(String [] args)
{
Q4Exception q1 = new Q4Exception();
try{
q1.sampleMethod();
try{
q1.sampleMethod();
}
//This catch does not throw an error
catch(RuntimeException es)
{
System.out.println("A");
}
//This catch below throws the error of cannot be resolved to a type
catch(IOException es)
{
System.out.println("B");
}
//This catch does not throw an error
catch(Exception e)
{
System.out.println("C");
}
finally{
System.out.println("D");
}
}catch(Exception e)
{
System.out.println("E");
}
finally{
System.out.println("F");
}
}
Q4Exception類
public void sampleMethod() throws Exception
{
try{
throw new IOException("H");
}
catch(IOException err)
{
System.out.println("I");
throw new RuntimeException("J");
}
catch(Exception e)
{
System.out.println(e.toString());
System.out.println("K");
throw new Exception(「L");
}
catch(Throwable t)
{
System.out.println("M");
}
finally{
System.out.println("N");
}
}
你導入'IOException'? – Reimeus
'import java.io.IOException' –