A rifle is a better choice than a pistol.
A pistol is a better choice than a knife.
A knife is a better choice than nothing.
I've always looked at handguns, in protective or defensive situations, as a tool that will maybe give me a chance to fight my way to my rifle. I much prefer a rifle.
I spent my first summer out of the service working as a helper for my cousin that was a guide in Alaska. When we were doing fishing trips, my job was to walk from client to client on the banks, telling them not to shoot the bears. Every man-jack-one of them had a brand new shiny monster pistol on their hip. I told them, all you're going to do is p*ss that bear off. I had my Winchester M70 in 375 H&H on my shoulder, loaded with 300 gr Partitions, and I told them if they shoot a bear, I may just let the bear maul them for a minute or two before I kill the bear. I was more worried about the clients doing something stupid, than the bears.
In our case, the bears are just after the fish. Worst case, just backing away and letting them have the fish was required. It was the "smaller", younger bears you had to worry about. The "big" bears got all the best fishing spots, leaving the smaller bears looking for fish.
I have to admit, in a couple of close encounters, that 375 did start to feel "small". Never had to shoot a bear in anger though.