I forgot to mention the Kernal function READST in my post from yesterday.
To sum it up, this is what I think you should do to handle I/O errors when reading a file:
Call SETNAM to set the file name. This function does not throw I/O errors.
Call SETLFS to set file no, device no and command. As I understand, neither this function throws I/O errors
Call OPEN to open the file
Check carry bit, if set there was an I/O error, and the error number is in A register
Call READST to get I/O status returned in A register. I not zero, there was an error. This should not happen on opening a file for reading, but could occur in other I/O operations.
Call CHKIN to open a channel for input
Check carry bit, as after calling OPEN
Call READST as after calling OPEN
Call CHRIN to read one character from the device
Carry set does not indicate error after calling this function
Call READST after every invocation to get I/O status returned in A register. It not zero there was an error or you reached end of file
Call CHRIN in a loop until READST returns end of file or an error
My experience is that the above mentioned Kernal errors only occur if there is a problem communicating with the device. For instance Kernal I/O error no 5 - Device not present - will be thrown if a SD card is not mounted.
But the Kernal will say nothing if the error occurs on what used to be the disk drive side in the old days. For example, a file not found error must be checked by reading the disk status. So the last step is to do that, which requires opening another I/O channel:
Call SETNAM (name may be empty)
Call SETLFS (like OPEN 15,8,15)
Call OPEN. Check carry bit and READST for errors as above
Call CHKIN to open channel for input. Check carry bit and READST for errors as above
Call CHRIN to read status string
Call READST and loop back and call CHRIN until READST returns end of file or an error
There are small variances on how to handle errors depending on the type of I/O channel, for instance if it's a RS232 channel instead of a disk file.
One good source for the functioning of the Kernal is here:
https://www.pagetable.com/c64ref/kernal/
It puts the comments on each Kernal function from a handful different books, including the C64 PRG, side by side.
Or in more simple terms. Use the Kernal functions. Even if you find some memory addresses that return the I/O status they might be subject to change.