In both cases DON'T format it, because you'd overwrite the data already being there, making it impossible to recover them.
Recovery is possible in both cases, but if it's due to a hardware failure, the only way is bringing your HD to a specialized lab and it can be very expensive. It's up to you to decide if the lost data are worth spending a big amount of money to try recovering 'em.
You could get through a "homemade" solution to this problem (I found this remedy on several web sites) but I suggest you to turn to it only as an extreme desperate attempt in case anything else resulted being no use and anyway i don't recommend it (even though in one case it worked for me).
Unscrew the hard disk from its case using a screwdriver (an external HDD in the end is a case containing an ordinary HDD), then put the internal hard disk into a freezer auto-sealing bag (kinda Ziplock).
Leave it into your freezer for several hours; then re-insert the HD into its case and plug it into your PC.
Hopefully this should temporarily solve the problem letting you access to data. Now copy all you can to another hard drive as soon as possible.
Sometimes cold helps a mechanical device to work again for some minute and it'll work as long as it'll start getting hot again so you gotta be fast and keep fingers crossed.
I repeat, use it only as an extreme attempt and anyway only if lost data aren't very valuable to you. A professional lab remains a much more reliable solution but a geek has to prospect all possible solutions to a problem, also the mos extreme ones.
If it's a data corruption problem and you can't solve it performing ScanDisk (activating the option "error correction' as already suggested) the only way is using software recovery tools.
You can find a bunch of them googling, but I suggest the following ones:
1) if you HDD is formatted using a NTFS filesystem, my choice is NTFS UNDELETE (freeware). I could recover 500 GB from an external hard disk using it without losing any data.
2) If your HDD is formatted with FAT32 filesystem, my options are RECUVA (freeware),