Thank goodness you recognized the situation and reacted in time!
Sometimes circumstances pile up against you, with no way to see it coming. For me there was always something I could have or should have done, and surviving I'm better for it ... hopefully there's something there you can build from to balance out the close call.