There is a great line from Rachel Cusk's novel, The Outline, which sums up the way we usually think. Our failures, as one of her characters says, keep returning to us, while our successes are something we always have to convince ourselves of. It's easy to remember where we went wrong and a little harder to remember when we did the right thing.
Is there an antidote to this? One thing that I was impressed with when I read Bill Stutz and Barry Michels The Tools is how simple and effective their recommendations are. If you feel bad, for example, simply think about all of the things that you have to be thankful for. The same approach can work with overthinking failure. If you have a tendency to ruminate upon your failures, make a list of your successes and memorize them. Then when you find yourself thinking about past mistakes, quickly move to consider your successes--convince yourself of them. This can go a long way towards ending fruitless thinking about the past.