需要您对以下代码的反馈 -
public static void main(String[] args) {
try {
throw new OutOfMemoryError();
} catch (Exception e) {
System.out.println("Inside catch");
} catch (Throwable t){
System.out.println("Inside catch throwable");
}finally {
System.out.println("Inside finally");
}
}
Run Code Online (Sandbox Code Playgroud)
在这里,我从try子句中捕获一个OutOfMemoryError对象(使用new运算符)并捕获Throwable对象.所以我得到输出"Inside catch throwable"和"Inside finally".但是因为我们抛出OutofMemError不应该代码退出(即没有进入Throwable&finally)?在实际的实际项目中,如果我们得到OutOfMemoryError,应用程序就会退出...为什么会出现这种差异?