I've always thought that the way to check that an SD.open() was succesful was as follows.
Code: Select all
File myFile = SD.open("/path/to/file.txt", FILE_WRITE);
if(!myFile)
{
// Oh no, myFile failed to open successfully
}
However, if I try to test this by removing my microSD card between writes, the above code doesn't pick up the error at all. I get a serial print of the error from vfs_api.cpp letting me know that the open has failed, but my if(!myFile) test doesn't work and so my code doesn't spot the error at all.
So it seems the examples are wrong? (Assuming others can replicate this issue.)
Is this a bug, or a specific case in which the above check isn't meant to work?
Does anyone have a method of checking if file opening has been successful?
Thanks in advance for any insight!