Java try-finally return design question

后端 未结 7 2186
滥情空心
滥情空心 2020-11-27 04:04

In Java, a try { ... } finally { ... } is executed somewhat unintuitively to me. As illustrated in another question, Does finally always execute in Java?, if you have a retu

相关标签:
7条回答
  • 2020-11-27 04:35

    the finally construct is a facility provided by the JLS to handle a code prone to some exception. the developer can utilise this facility to ensure a graceful recovery from an exception. to use the finally construct in the manner you've described doesn't make for a good practice. for that matter, it is never good to return anything from the finally block.
    so as you asekd, the "philosophy" is to handle any abrupt completion of code. if returning a certain value as part of handling such a state is required, that should be done within the catch block.

    0 讨论(0)
提交回复
热议问题