What happens when writing to a file during a power failure?

I’d be putting a UPS on any critical computer that is subject to potential data loss due to power outage. The app could detect when the power status has changed and then save/exit the app if desired.