"Finally block does not complete normally" warning resolution

Source: Internet
Author: User
Tags finally block

Reprint Address: http://www.cnblogs.com/interdrp/p/4095846.html

Java inside is not guaranteed to finally will be executed, why not in finally block to do return.

To look carefully:
Debug this function, you will be surprised to find that the exception thrown inside will be finally eaten. That's why they're being warned.

@SuppressWarnings ("finally")
private Boolean isreturnwithinfinally ()
{
	try {
		if (true)
			throw New RuntimeException ();
	} Finally {return
		(TRUE);/* This hides the exception */
	}
}
So, the following is OK. Deal with the exception first

public static void Main (string[] args)
{
	try{
		throw new RuntimeException ();
	} catch (Exception e) {/* */
	}
	finally {return
		;}
}
The conclusion is: Still not. The exceptions in Java are divided into two classes that are not captured and cannot be captured, even if the catch block is used, which can result in a catch-only error being eaten.
Therefore, return must be put to finally outside.


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.