V6135. The return value of the 'finally' block overrides return values of 'try' and 'catch' blocks.
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 is classified as:
|