The analyzer has detected an error related to overriding the return value from a try/catch block within a finally block.
The example:
try {
return getResponse(....);
} catch (Exception e) {
....
return -1;
} finally {
....
return 0; // <=
}
When the return statement is executed from a try or catch block, the control flow enters the finally block before exiting the method and executes all the statements within it. As a result, the last executed statement is return from the finally block, which overrides the return value from the try or catch block.
The fixed code may look as follows:
int answer = 0;
try {
answer = getResponse(....);
....
} catch (Exception e) {
....
answer = -1;
} finally {
....
return answer;
}
This diagnostic rule is classified as:
|
Was this page helpful?
Your message has been sent. We will email you at
If you do not see the email in your inbox, please check if it is filtered to one of the following folders: