对于我在Java中的最后一次测试,我们在测试中有一个“异常”部分,包括try、catch和最终调用。当我尝试将示例代码放入Eclipse中时,我会在捕获中得到错误并抛出新的区域。所有的错误都说“无法解决键入”。
我如何解决这个问题,以便学习/检查代码应该做什么?
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");
}
} 发布于 2013-12-12 18:56:13
我认为值得一提的是,在Eclipse中,Ctrl+Shif+O完成了为您解析导入的工作。
发布于 2013-12-12 18:37:50
哦,我想我可以在这里回答我自己的问题。不知道我必须从IOException中导入java.io!
发布于 2016-03-03 16:42:45
简单易用
import java.io.*进口品
https://stackoverflow.com/questions/20551475
复制相似问题