Do you have return,finally in Try Catch finally,try?

Source: Internet
Author: User

Condition 1: If there is no exception in try and return in Try (execution order)


Condition 2: If there is an exception in the try and return in Try


In short, finally always execute!

Condition 3: There is an exception in the try, there is no return in the try-catch-finally, finally there is a return


If there is an exception in the try, then execute finally after catch according to the exception mechanism of Java, at this time the error exception has been thrown, the program terminates because of an exception, so your return will not be executed

Condition 4: When there is return in try and finally, the return in finally will overwrite the return of the other position (multiple return will be reported unreachable code, the compilation will not pass).

Condition 5: When return does not exist in finally, and return is present in the catch, but finally in the change value of return in the catch

0;try{     thrownewException();}catch(Exception e){    1;  return ret;}finally{    2

The last return value is 1, because the return value has been determined before the finally run.

Do you have return,finally in Try Catch finally,try?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.