I know that returning in the finally block would lead to undesired results like uncaught exception getting lost. But what I am trying to understand here is Eclipse's suggested fix for the warning "finally block does not complete normally"
.
Consider this code snippet:
catch (SQLException se)
{
System.out.println("Exception occured in the database");
System.out.println("Exception message: "+ se.getMessage());
System.out.println("Database error code: "+ se.getErrorCode());
se.printStackTrace();
}
finally
{
// Clean up
if(callStmt != null)
{
try
{
callStmt.close();
}
catch (SQLException se2)
{
se2.printStackTrace();
}
}
if(conn != null)
{
try
{
conn.close();
}
catch (SQLException se2)
{
se2.printStackTrace();
}
}
return newEmpSalary;
}
}
For the above code Eclipse Luna
gives the warning "finally block does not complete normally"
, for which the suggested fix is:
Applying the above fix still does not make the warning go away.I know I just need to remove the return statement to get rid of it.
But I am curious to know why Eclipse is suggesting the fix "Change modifiers to final where possible"
in this case.
Eclipse can't always figure a way out of the error so it suggests other things that might help or lead to a different error it does know how to fix.
Moving the
return newEmpSalary;
out of the finally block should remove the error.