It depends on what kind of failure were talking about, but generally it comes down to not focusing on the failure, and instead asking what you can do now. Your can't change the past, Burt you can do the next right thing.
For me, I felt my entire life was a failure when I was 20. Rather then focusing on what I could do to improve my life, I tried to run away from all of there pain. I started using more and more drugs. And as the drugs made my life worse and worse, I kept using more and more to help myself cope. By the time I was 21, my arms were covered in bruises from pricking myself. I had sold off anything of value I owned. I had already borrowed (with no intention of paying back) as much as I could get from everyone I knew. I was miserable and alone. Has I died at that point, I doubt anyone, save immediate family, would have came to my funeral.
Coming back from my life being a complete failure wasn't easy. But as the old saying goes, when you find yourself in a hole, the first thing you should do is stop digging. And that's what I did. I started going to meetings, and when I went there, their were people who had been in my exact situation who now had great lives. And, for the first time in years, I had hope that I wouldn't be always be a complete failure. I went to rehab, and gradually just kept trying to do the next right thing.
I guess that's the only way to come back from a failure, just keep doing the next right thing. You can't change the past, and beating yourself up about it won't help anything. The key is to just look at the situation, and instead of asking what should I have done, instead ask what is the best thing I can do now.