14.2 In Java, does the finally block get executed if we insert a return statement inside the try block of a try-catch-finally?

 

这道题问我们Java中的finally块是否会被执行,当我们在try中加入了返回return。

答案是即便try中加入了return或者continue或者break等命令,finally块仍然会被执行。但是下列两种情况下finally里的内容不会被执行:

1. 当虚拟机Virtual Machine在try/catch模块中就退出了的时候

2. 当线程在处理try/catch模块就结束了的时候

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-07-14
  • 2021-08-16
  • 2021-11-11
  • 2021-12-16
  • 2021-11-12
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案