An alarm would not work for me very well as I typically sleep with earplugs, otherwise I cant get to sleep and get woken up frequently. On the rare times I stayed in crowded shelters they were a great help.
The electric fence for polar bears and dense grizzly country are used, not always with success, there was artic researcher from Maine several years ago that got severely mauled in the Artic by a polar bear that apparently walked right through the fence. I have run of the mill black bears in my area and they were getting into my berry bushes. I talked to a local expert and he recommended a high voltage fence and training the bears that the fence is there. The trick is to take strips of tin foil with peanut butter on them and wrap them around the fence wires before the berries are ripe and then leave the fence on. The bear will come up and smell the peanut butter and try to lick it off. That trains the bear that there is fence there. After a season or two I didn't need to turn on the fence, as long as the wires were in place they left the berries alone. On the other hand beekeepers have to use two sets of fences plus train the bears with peanut butter and even then they on occasion will get raided.