I think getting a gun for this is pretty dumb. If you keep your guns at home, it's just one more thing that will get stolen next time. They are only effective if you have them on you. If the guns are in your home, they could even use them against you if you break in on them. Also, self defense laws are fucked up. If you shoot and kill a home invader, be prepared to have a self defense story that they were trying to kill you, not just rob you. I disagree with this stance, but that's how the law works. One other thing, I actually doubt the home invaders are packing guns or knifes themselves. They might have some blunt instrument that helped them break in or a knife from your home, but unlikely anything else. My guess is they plan on just not getting caught. They never planned on you ever catching them. They also would probably just run if you did catch them.
Best home defense you can get is a security system. The next best home defense is a big dog. Dogs are very protective, and they will bark at intruders. These two are far more likely to prevent a break in from happening, so they are much better. In the situation you described, a gun would have done you nothing, because they were already gone.