A detailed analysis of the try, catch, finally in Java

Source: Internet
Author: User
Tags finally block

From: http://www.cnblogs.com/aigongsi/archive/2012/04/19/2457735.html

To summarize all the examples

1 in a try, catch, finally statement, if the try statement has a return statement, then the value of the variable in the current try is returned, and any subsequent modifications to the variable do not affect the return value in the try

2 If there is a return statement in the finally block, returns the return statement in the try or catch is ignored.

3 If an exception is thrown in a finally block, an exception is thrown in the entire try, catch, finally block

So the use of try, catch, and finally statement blocks should be noted

1 Use the return statement as much as possible in a try or catch. It is not feasible to modify the return value of a try or catch by reaching the finally block.

Avoid using the return statement in the 2 finally block, because if the return statement is used in the finally block, the exception information in the try, catch block is displayed, shielding the error from occurring

3 Finally block avoid throwing an exception again, otherwise the entire method containing the try statement block throws an exception, and the exception in the try, catch block is digested

A detailed analysis of the try, catch, finally in Java

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: info-contact@alibabacloud.com 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.