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.