Plenty of money management methods are available which prevent this error by design.
Do not rely on any facts other than those which are spelled out in the fine print of a valid written contract.
Awhile back, while I was living and working in California, I had an ATM card which, to my extreme surprise, permitted me to buy some groceries despite the funds not being available in my account. It turns out that smaller institutions are more likely to balance the books at the end of the day, rather than instantly. Sure enough, I reread the fine print of my contract, and it did spell out that I was exclusively responsible for keeping my own ledger -- and the 'check your balance' feature on their ATM machines did not necessarily reflect the actual balance; it could be several days out of date!
Today I use a NetSpend card that I bought from the Money Box near my house. I walk over there and give them cash, and this ordinary-looking credit/debit card functions normally until it is empty. If there's no money in it, the transaction is simply declined. But perhaps most important, I immediately receive an SMS message on my mobile phone listing the transaction details and the remaining balance, accurate as of that very instant.
 bonus points for their use of the 'King and I' reference on their et cetera page; negative points for their use of pop-up windows.
 although I have found that, after many cycles of my reliably filling and emptying the card, they will allow one and only one final transaction to exceed the balance by a tiny amount, as a convenience. I'm pretty sure they'd stop doing that if I asked them to.