SD.h library - error handling.

I've written a library that will write messages to both the screen, and an SD card using the SD.h library.

I've noticed that if I forget to insert the SD card or there's a hardware fault I get the following error....


I've dug around in SD.h, and it seems that this error comes when the init() method is run on the Sd2Card object.

Fair enough, there's a problem, and the code has generated an error, as it should. However, what I'd like to do is be able to skip and ignore this error. As i said, my library is designed to write messages to both the screen and the SD card, if the SD card isn't available then obviously it my project can't write to it, but I'd still like it to carry on and display to the screen. At the moment I get this error and everything stops, is it possible to just bypass it and continue?

I've not include any code, I beleive the message comes from within SD.h which I believe is now included in the arduino package. (it's also beyond my level of understanding, so I haven't been able to dig into it too far)


How do you get that error? SD.begin() returns true on success and false on fail.

What device are you using? Is it just an SD card or some other device on the shield also? Any other SPI devices connected to the Arduino?

At the moment I get this error and everything stops

Most likely, because your code tells it to do that.

is it possible to just bypass it and continue?


I've not include any code



I've not include any code

the message appears to be coming from within SD.h which everyone should already have.

This line (343) appears to be raising the error...

  return card.init(SPI_HALF_SPEED, csPin) &&
         volume.init(card) &&

since this is a 'standard' library, I assumed it was a standard error. Obviously I was wrong! I'll try to knock up a quick sketch to illustrate.


Ok, finally realized where the error is coming from.

I've started a new thread for this one...