对于我在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' –