One of my laptops used to immediately shut off. This always happened to me when I was in the middle of working on something important. Since the shutdown was immediate, not graceful, I would lose all my unsaved work.
I noticed this usually happened after the fan had been running. The fan would run at high speed for a while, then the computer would immediately shut off.
After a few months of this, my amazing powers of deduction led me to take apart the computer looking for some hardware issue. Here is what I found:
Apparently, there was a lot of dust blocking the fan exhaust. Once I removed all of this, the computer has always worked perfectly. It has not shut off automatically in 6 months.
I have no idea where this dust came from, by the way. I promise we are clean people!