java - 如果在 catch 子句中抛出异常,finally 仍然运行

标签 java exception try-catch

考虑到下面的代码,如果 catch 子句中抛出异常,finally 是否仍然运行?

try {
//code here throws exception
}
catch(Exception ex) {
//code catches above exception however code here also throws another exception
}
finally {
//does this code even run considering the exception thrown in the above catch clause??
}

最佳答案

是的。无论 try/catch 中发生了什么,它都会运行(假设 JVM 由于某种原因没有关闭)

关于java - 如果在 catch 子句中抛出异常,finally 仍然运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10308184/

相关文章:

sql - 我无法使用 THROW SQL Server 2008 R2

java - Teradata CLOB 和 JDBC : The Locator is invalid because it has been changed ERROR

java - Kaitai结构体代码异常 "java.nio.BufferUnderflowException"

java - 将一些代码放在 try catch block 中可以通过哪些方式阻止 JVM 进行优化?

c++ - try and catch in C++ - 创建了多少个对象

.net - 仅使用Exception类作为传输机制?

java - 在 Java 8 中是否有更简洁的方法来执行此操作 - map 操作

java - RxJava - 观察可能总是变化的数据

JavascriptExecutorexecuteScript 不返回

exception - Grails 2.4.4 : How to reliably rollback in a complex service method