Photoshop is a very solid piece of software, but as every other software, it tends to crash from time to time. For me it’s sometimes happens when I use a plug-in, or work with a very big image, and each time I of course forgot to save my work beforehand. But that’s normal, as the crashes are so rare, I never developed the habit to save regularly :)
Have auto recovery save on
One can’t really prevent a crash, but one can be prepared for one. You could either learn to save regularly, or even better, use the Photoshops auto save function. This is turned on by default, but it’s set to every 10 minutes. I think this is a little too much time. I suggest changing this, so it saves a copy every 5 minutes. If you are painting in a mask, 5 minutes is a long enought time, to do a lot of work.
You can find this setting under Edit/Preferences/File Handling/Automatic save recover information every. There you can also change how often it’s saved.
There is also a second setting here, that should stay on, that is Save in Background. This is so you are not interrupted in your work while Photoshop is saving.
What to do after crash?
If you are lucky, and Photoshop saved a backup, once you open it again, your file will be loaded automatically. If it does not load, you still have a chance to get it.
What you need to do, is go directly into Photoshops Auto recovery folder, where it saves all the backups as PSB files (PSB is almost same as PSD, it just supports bigger files, it can be opened in Photoshop). You can find the folder under System drive (C:)/Users/ your user name here/AppData/Roaming/Adobe Photoshop (CS6 or CC)/AutoRecover. It’s possible you will not see the AppData folder, as it’s hidden. In that case you have to go under View/Options int the File explorer, and in the tab named View turn on Show hidden files. Be careful opening the files in the AutoReover folder directly in Photoshop, as when you do, Photoshop will delete the recovery immediately. I suggest copying them to a separate folder first.
This is all under Windows 8 and Windows 8.1. Under Windows 7 this will be very similar, but I can’t really tell where the folder is on a Mac, as I don’t own one, and can’t try it out :)
Btw. for a little more info on crashes, check out the very first comment under the post by Foster Brereton (fbrereto)