
1 ysc3839 2024 年 3 月 19 日 via Android return 也会执行 |
2 google2020 2024年 3 月 19 日 try 或 catch 可以 return ,return 之后外面的就不跑了,但 final 会照样跑 |
3 mxT52CRuqR6o5 2024 年 3 月 19 日 其他语言不清楚,js 的 final 块可以改变 try/catch 中已经 return 的返回值 |
4 geelaw 2024 年 3 月 19 日 楼上已经说过 return 的时候 finally 会执行,把必须执行的代码写在 finally 里面而不是后面对阅读更好。另外就是 try { throw something; } catch { throw; } // 重新 throw finally { other; } another; 里面 other 是会执行的,another 不会执行。当然你可以说 another 可以挪到最外面的 catch 后面,但是这样会导致整个程序不能非平凡地使用方法,因为最外面的 catch ,在一段“正常书写”的代码里,不一定在当前方法里面。 |