以下是我的代码,当我评论 statements-2 时,它符合罚款要求,但当我取消注释时,它会给出 Compile Time Error "Unreachable Code"。
我明白为什么我在取消注释后收到错误,但我的问题是,即使我注释它仍然bad()无法访问,因为我是throwing一个异常,那么为什么它没有给出错误?
class Varr
{
public static void main(String[] args) throws Exception
{
System.out.println("Main");
try {
good();
} catch (Exception e) {
System.out.println("Main catch");
//**Statement 1**
throw new RuntimeException("RE");
} finally {
System.out.println("Main Finally");
// **Statement 2**
throw new RuntimeException("RE2");
}
bad();
}
}
Run Code Online (Sandbox Code Playgroud)