已提出类似问题here 。但这并没有提供答案。
try {
object = (Dev)Class.forName("Dev").newInstance();
} catch (Exception e)
{
throw new RuntimeException("Devis not available");
}
finally
{
return object;
}
但是finally block 发出警告:
finally block does not complete normally
但根据我的轻描淡写,finally block 总是会被执行并返回对象。为什么警告说无法正常完成?
最佳答案
问题是finally block 会删除任何抛出的异常,因为它会发出“正常”返回。
来自JLS spec :
Abrupt completion of a finally clause can disrupt the transfer of control initiated by a return statement.
和(与您的情况更相关):
Note that abrupt completion of a finally clause can disrupt the transfer of control initiated by a throw statement.
关于java - return 语句 - finally block 未正常完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22781437/