Our vet advised us to get an invisible fence for our pets, and I put a couple of our cats on it. Our dogs I was able to train to stay home without the fence. The fence works very well for one of our cats, he has used it for 13 years now. He's so well trained to stay at home that I haven't even put the collar on him for a few years. Another cat though, he never did get the "message". He would just run right through the fence, coming and going.
We got our fencing system from "Invisible Fence Company". It has an automatic shut off, so that if a pet stops and stays over the fence while being shocked, it will shut off after a few seconds. So the animal isn't going to be shocked to death if it panics and drops to the ground over the wire. And I don't keep the collar on too tight, either. I do know someone whose dog has the collar, and it bothers me that they keep it on so tight. They insist it's necessary. (it really isn't) Thankfully, they do take the collar off their dog at night. But I think that used properly, and if using a good quality fencing system, they are wonderful containment systems for cats and dogs. (there is no "gap", I don't understand how there could be a gap in an invisible fence??)