Acording to RTL reference guide
76.15.111 FileSeek
Synopsis: Set the current file position on a file handle.
Errors: On error, -1 is returned.
Description: FileSeek sets the file pointer on position Offset, starting from Origin....If successful, the function returns the new file position, relative to the beginning of the file.
The following code can be found in the development(trunc) of rtl/unix/sysutils.pp:
Function FileSeek (Handle,FOffset,Origin : Longint) : Longint;
Var
I : Int64;
begin
I:=FileSeek(Handle,int64(FOffset),Origin);
if I>High(Longint) then
Raise EInOutError.CreateFmt(SErrPosToBigForLongint,[I]);
result:=I;
end;
As can be seen, on error the function may return -1 but it may raise exceptions, too. Should the documentation be updated?
Should I understand that the appropriate programming practice for using FileSeek is including it in a "try if FileSeek<>-1 then begin...end; except/finnaly end;" block?
Wouldn't be better if the function would return a negative value different than -1 instead of that exception, for example error code -2 or something?