Best Practices: error detection and handling

I have a fairly random approach to error detection and handling in my apps and was hoping to poll the forum to improve my (and maybe the community’s) knowledge base.

I’d divide the topic into 2 sections: 1) detecting and handling errors outside my control like garbled characters coming in on a serial port and 2) defensive coding techniques like making sure while or for loops don’t index past the end of a fixed length array.

Are there useful books or articles on these topics?

If you’re interested in this topic, feel free to contribute the tools, techniques and/or code snippets you’ve found effective.

Cheers - Gene

[quote=“Gene”]2) defensive coding techniques like making sure while or for loops don’t index past the end of a fixed length array.
[/quote]

I’d recommend unit testing for these type of scenarios. Some books that discuss these general coding strategies are “Code Complete” and “Writing Solid Code”.