Yes and no. Sure, you could hypothetically shoot someone before they do any harm, thus defending yourself. However, odds are very slim of that happening, even with training. Cases of would-be burglary thwarted by shooting are the rare exception, not the rule. Besides that, most studies though that criminals are much more afraid of a dog than a gun when breaking in (I'm too lazy to find the link, but if you're really that doubtful, research yourself).
I think part of the problem is too many people assume it will go down like they are cowboys or something. They'll just do a quickdraw and shoot him first! In the street though they will likely get the jump on you or outnumber you, and in your home they are likely to break in while you're out. Guns don't stop bullets, they just throw more out there. But yeah, it can be used for self-defense, I just wouldn't bet on it.
Oh, and those saying "shoot him in the leg" I doubt have ever used a gun before, or at least not properly. Leg shot doesn't mean non-lethal necessarily, femoral artery and all. Also, all shots should be considered killing shots with the intent to kill, that's what a gun is FOR. And most importantly, you will in all likelihood miss, or not even slow the attacker down. Pelvis will ground someone if it's a large enough round, leg or foot though, could easily keep coming. It's relatively small target moving fast, leg shot is dumb. Shots should be in the torso or, if there's cover/armor/numerous other things, the head.
...Or are we talking legally? Because that depends on where you're at...