Moto G 3rd Gen - SD Card stopped working
Unfortunately I only have the answer for the first part of your question. There are many reasons why an SD Card can go corrupt. (e.d. Physical Damage, not removing it properly etc.) As far as the latter is considered, Android has the option to eject the SD Card in Settings before you physically remove it from the phone. This option exists only to serve this one purpose, to stop things like this from happening (e.d. getting your SD Card corrupted). 

I don't think there is much you can do at this point but reformat it, which of course as you probably know deletes all of your files.

HOWEVER do NOT reformat it still only because I am not familiar with any options of restoring it to proper function. I have heard of different types of software that claim they can do the thing for you, BUT be careful! As they are many of them that come in a form of some malware.