miskox wrote:Thanks for the solution but the problem remains
Of course, only the PureBasic developers can change that. We can only create workarounds.
miskox wrote:I think that the application should just rely on 'errorlevel'* and should not include ten, hundred, thousands of lines of code to do the errorchecking.
You're exaggerating.
The error checking code is very small in this case.
Shouldn't it return negative* value or value >255 if there is an error? But how could this value be returned (ReadByte has .b and ReadAsciiCharacter has .a type)?
Because byte read from the file can have a value of zero?
The problem is that the function returns only one value and the value range is already exhausted and therefore no more value can be reserved for an error. You already realized that. Using a value outside the valid value range of the return type is not a good idea, because the value swaps when an overflow occurs:
Code: Select all
value.b = 127+1 ; Value is over valid value range (byte: -128 to +127)
Debug value ; -128 -- No error recognizable, because the value is in the valid value range
It would probably be best if the read functions had one more parameter to which you could pass an address to a variable that receives the error code:
Code: Select all
value = ReadByte(file, @error)
If error = #False
Debug value
Else
Debug "Error"
EndIf
Or a new function:
Code: Select all
value = ReadByte(file)
If GetLastFileError(file) = #PB_FileError_None
Debug value
Else
Debug "Error"
EndIf
We can discuss which variant is better and then create a feature request.