I'm a big fan of avoiding the bears. If that doesn't work, handguns are a very last resort.

For cartridges that are unlikely to immediately stop a bear, including any handgun, my hope would be to have the time to convince the bear that I am not food, perhaps by firing the pistol into the ground nearby. If I have to shoot at a bear with a 9mm pistol, I'd expect to attempt headshots at the fastest speed I could make hits until one of us stopped. I'm very good with a handgun but a 9mm against even a small black bear is desperate straights indeed.