I've actually had close calls like that, too. One day I wasn't at my usual computer, but I wanted to work on my story, so I downloaded this program that had a word target feature, so I could at least write to the number of needed words.
When it came time to save, the program
crashed. It didn't save. I was lucky that it was, however, keeping backups in a different location every couple minutes, so in the end I only lost a couple paragraphs.
I also use a version control system so I have multiple backups and don't lose any work over time. Worst case, I might lose what I was writing at that moment, but not what I wrote before...