I often use code along the lines of:
function GetNumber(Handle : THandle) : Integer;
begin
FLock.BeginRead;
try
if FMap.TryGetValue(Handle, Object) then
raise EArgumentException.Create('Invalid handle');
Result := Object.Number;
finally
FLock.EndRead;
end;
end;
Unfortunately the compiler gives me a warning for all these methods:
[DCC Warning] Unit.pas(1012): W1035 Return value of function 'GetNumber' might be undefined
I know this warning, but in this case I can't see any reason for it at all. Or is there a scenario that I am missing that would result in an undefined result value? I understand the warning in the case of try..except
but for try..finally
it does not make sense to me.
Questions:
- Is there any reason for the warning?
- How can I get rid of it (moving the
Result := Object.Number
line out of the lock is not an option, and I want to avoid writing an completely unnecessaryResult := 0
line at the top of each function)
Thanks!