When the implementation in both the try and finally return

function try the function return statement before the call finally called in to perform, that is, try to execute the return statement is executed after finally statement, but try not to make the return function returns the result immediately, but return statement after execution, the function will return the result placed into the stack, then the function does not return immediately, it is to be executed before finally statement really began to return. But this time there will be two cases:
① If there are finally in return, will finally result in a direct return to return, and to terminate the program, function stack of return will not be completed
② If finally there is no return, then the implementation of End after the code is finally, try return function will save the contents of the stack and terminates the program returns

note:

1, whether or not abnormal, the finally block of code will be executed
2, try and catch when there is return, the finally still performs
3, finally is (in this case did not return after the calculation expression executed later try the return value after the operation, but saved first value to be returned, how the code sample tube finally, the return value will not change, still the previously saved value), the function return value is performed before finally determined
4, finally is best not to include return, otherwise the program will exit early, the return value is not try to save or catch the return value

Published 10 original articles · won praise 0 · Views 176

Guess you like

Origin blog.csdn.net/hblack_313/article/details/104256368