当我使用下面的代码,编译错误发生。好奇,是否条件和例外
try {
throw new Exception("Exceptionist");
System.out.println("another line"); //compilation error
}catch (Exception e) {
System.out.println("Exception:" + e.getMessage());
}
编译错误的原因是我们不能在抛出异常后编写代码。 但是,当我尝试这样的事情
try {
if (true)
throw new Exception("Exceptionist");
System.out.println("another line"); // no compilation
} catch (Exception e) {
System.out.println("Exception:" + e.getMessage());
}
即使在Eclipse IDE预测syso死代码,为什么不是Java点出来。即使它被编译成字节码,syso也不会被执行。那么为什么它不被视为编译错误。 (我知道它不是一个编译错误:|。可能是,表示它的一些其他方式)它是给程序员的选择吗?