It depends. I quite often carry my G-26 or C-19 on trails where there is no possibility of bear encounters. In almost any situation where you might need a gun in the woods it will be for 2 legged predators and I'd plan for that 1st. A 9mm is as good as any and better than most for that use.
When hiking where bear live I carry a G-20 with hot 200 gr. hard cast bullets @1300 fps in 1 mag and a 2nd mag with 155 gr HP ammo for 2 legged threats. I think this is the best compromise handgun for my uses.
But sometimes you have to run with what you have. If a 9mm is what I had, and no bear was a possibility I'd be perfectly content to carry it with any load I had confidence with in town. While not ideal, if the threat of larger predators were a possibility then that would be the load I'd carry.
Black bear are not bulletproof nor hard to kill. You don't need a 44 mag for any of them. A 357 or 10mm is more than enough and 9mm, 45, and 40, while not ideal, are much better than many give them credit for. And certainly better than nothing. While there are rare 400-600 black bear they almost never bother humans. They don't live long enough to get that big by hanging around humans. The average size of problem bears are young 150-200 lb bear that are no tougher than a very athletic human of the same size.