I always get stung. You basically have two options:
1) Run as fast as you can into the nearest building
2) Quickly whip out your net and try to swipe one, they sell for 4,500 bells each
Otherwise, you're screwed. I normally but some medicine from Nook before i go tree-shaking, and wait to use it until i've been stung a couple times in a row or i'm done tree-shaking. If you buy insurance from Lyle, he'll mail you 100 bells the next day if you get stung.