return statement in java exception handling

This question already has an answer here:

  • Does finally always execute in Java? 50 answers
  • Java's return value in try-catch-finally mechanism 4 answers

  • Because finally block will be executed every time whether you enter in try or in catch , I think that's why its called finally :)

    FROM JAVA DOCS

    The finally block always executes when the try block exits. This ensures that the finally block is executed even if an unexpected exception occurs.

    Note: It won't be executed only when

    If the JVM exits while the try or catch code is being executed, then the finally block may not execute. Likewise, if the thread executing the try or catch code is interrupted or killed, the finally block may not execute even though the application as a whole continues.


    按照设计, finally块中的返回总是优先。


    Finally will get called last no matter if the catch block is called or not. Perhaps you want to read more documentation. MSDN Try Catch Finally

    链接地址: http://www.djcxy.com/p/73702.html

    上一篇: 在try,catch和finally中执行的顺序是什么

    下一篇: 在java异常处理中返回语句