Proper exposure is one of the trickiest things to get right in photography. There are so many factors within the camera that can affect the exposure, and it all depends on the lighting and whether the subject is moving. Shutter speed, ISO sensitivity, f-stop, all of these things affect exposure and can make the difference between a great shot and a worthless shot.
The easiest and best way to ensure that you get a proper exposure is by bracketing. Take multiple photos of the same subject under the same conditions, changing settings like f-stop and shutter speed with each shot. Out of the pile of photos you get, at least one of them should look good. Many cameras offer automatic bracketing, which lets users cycle through a range of exposure values with the touch of a button, removing the need to go menu-diving for each shot.
An overexposed photo
In general, strictly based on how the image will look after you "fix" it, it's better to overexpose a photo than underexpose it. By reducing the exposure, the final picture might have some skewed or muddled colors, but everything in frame will at least appear sharp. Even if the photo looks completely blown out, you can pull down the exposure to produce an at least somewhat usable picture.
The same overexposed photo, corrected in Photoshop
An underexposed photo
Overexposure isn't always and option, and sometimes you'll have to settle for underexposure. If you're taking photos at a concert or a night club, the lights will be low or the subjects will be moving, and you simply won't be able to get a decent exposure, and you certainly won't be able to overexpose. In those cases, you'll simply be resigned to underexposure. The best way to limit the damage to the picture is to maximize the ISO sensitivity and use the widest f-stop your lens can reach. You'll still have to deal with graininess, but it won't be quite as bad as it would be otherwise. Just be sure to watch your shutter speed; no post-processing can fix a blurry, moving subject. It's better for the final picture to be noisy than completely unusable.
The same underexposed photo, after an attempted Photoshop fix