Java try-finally return design question

后端 未结 7 2366
滥情空心
滥情空心 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:34

    check this for reference  Does finally always execute in Java?

    "A try statement with a finally block is executed by first executing the try block. Then there is a choice:
    If execution of the try block completes normally, [...]
    If execution of the try block completes abruptly because of a throw of a value V, [...]
    If execution of the try block completes abruptly for any other reason R, then the finally block is executed. Then there is a choice:
    If the finally block completes normally, then the try statement completes abruptly for reason R.
    If the finally block completes abruptly for reason S, then the try statement completes abruptly for reason S (and reason R is discarded)."

提交回复
热议问题