原文地址:https://www.cnblogs.com/wyisprogramming/p/6610950.html

finally 语句块中, 最好不要使用return, 否则会造成已下后果;

1, 如果catch块中捕获了异常, 并且在catch块中将该异常throw给上级调用者进行处理, 但finally中return了, 那么catch块中的throw就失效了, 上级方法调用者是捕获不到异常的. 见demo如下:

 

2, 如果在finally里的return之前执行了其它return , 那么最终的返回值是finally中的return:

 

相关文章:

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