I tend to program very iteratively. Instead of writing a program that does everything, I'll write a program that's very good with a small fraction of the common cases, and crashes instantly if it runs into something it's not really prepared to deal with. I put these crash-instantly lines all over the place (many of you probably know them as asserts, but if you're not a coder, just ignore this bit inside the parenthesis) and they serve me very well.
Program behaving weirdly? Not anymore - now it just crashes with a useful diagnostic message!
Input data inconsistent? Who cares - it'll just crash with a useful diagnostic message!
The nice thing about this is I spend very little time figuring out where a bug is occuring. It tends to crash. Very quickly.
The disadvantage is, in cases like this where I have very iffy data to start with, I can often go a day or two without actually ever managing to run my code all the way through because it keeps hitting asserts and crashing.
But at least I know the results are good. So in the end, it's great . . . just irritating.