As someone who lives out west, and deals with bears on a fairly regular basis (while hunting, around town, in my yard, in my house… you know, normal stuff…) I HIGHLY HIGHLY recommend bear spray. It is far more effective, especially in lightly trained hands.
If you don't have a lot of experience with a handgun, and aren't going to practice with it religiously and in high pressure situations (which the vast majority of people don't/can't) it's not going to do you a lot of good.
Spray, on the other hand, is easy and effective. Build a wall/cloud in front of you- and they stop in their tracks.
If you really really want a hand gun (which I encourage),, get one you will carry and use for your whole life. Don't just get one for western hunting. A 9mm is a great choice for a new owner, as it has manageable recoil and you can easily learn to put rounds where you want them.
I've been carrying for almost 20 years, and still carry a 9mm. I wouldn't hesitate to shoot a black bear with a 9mm. If you put the rounds on target, it will be effective. If you miss with a .45, or don't put them in a lethal spot, it won't magically bring the bear down more than a 9 would.
I carry a 9mm when I am clearing the yard of troublesome bears. But it is always secondary to my bear spray. I ONLY carry bear spray when I am out hiking and hunting. Also, make sure whatever you are carrying is easily accessible. I see people with spray/guns strapped to their packs and it is worhsless weight. Even on your hip can be problematic, if you are face down or in the fetal position with a bear on your back. I carry spray strapped to the front of my chest. Doing this saved a Ranger's life a few years ago, as a grizzly had her by the back of the skull pinned down. She pulled the spray off her chest, and shot it over her shoulder. She said had it been on her hip, she pick have never been able to deploy it.
If you want a gun, get something you will shoot often, learn to shoot well, and train to shoot well under pressure. But if you want protection from bears, get bear spray.