Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.
Is it plugged in or on battery? Did you check the power settings? If it suddenly shuts off while on battery power it could be a bad battery cell. I had one go out on me once and the battery would go right from 40% to 0%.
 
I've had several 2012 Airs with this problem. Make sure your firmware is up-to-date (Software Update), reset the SMC, and failing that you might need a new battery or logic board.
 
I've got a 2012 MBA, less than 2 months old, that kept shutting down all by itself. Even if it was asleep when you woke it up, it would claim it was recovering from a restart.

Looking on various forums tried rebooting the laptop with the 'D' key this would then try the various boot tests and it would fail on the memory.

One genius appointment later and laptop was back a couple of days later having replaced the logic board and the fan. £330 Repair, all covered by warranty.

Not the best start for my Apple owing experience, but the Genius bar does help. Would have been repaired that day if they'd had the board in stock.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.