Zac*_*ase 3 java exception try-catch
对于我在Java中的最后一个,我们在try,catch和finally调用的测试中有一个"例外"部分.当我尝试将示例代码放入Eclipse时,我会在catch中遇到错误并抛出新区域.所有错误都说"无法解析为".
我如何解决这个问题,以便我可以学习/检查代码应该做什么?
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");
}
}
Run Code Online (Sandbox Code Playgroud)
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");
}
}
Run Code Online (Sandbox Code Playgroud)