Since this apparently needs to be repeated: you don't write reliable code by "being really careful" or "avoiding mistakes".
You do it by accepting that you *will* inevitably make mistakes, and designing your code so that the likelihood and/or impact of those mistakes is minimized.