Personally I just get back on the bike and keep going. In fact I wouldn't even stop (get off) until I got to the top, you are just prolonging the eventual pain. The only time I have ever or will ever again get off and walk is if I can't turn the crank over at all no matter how hard I try. As far as heart rate unless you have reason to believe you'll have a heart attack if you go above your "max" it's ok for a seconds. Most likely you won't be able to get that close anyway. Now if you start to get lightheaded, dizzy, or see stars, stop and sit right away.
I had an expirence back before I had my heart rate monitor and was in totally horrible shape (240lbs and no training) tried to maintain only 17mph for a long time and blacked out while riding. I really don't know what happened except everything went black for a second and then I came back and kept on going, I did slow down a few seconds later though. It all happened so fast that the group I was with didn't even know what happened apparently in those few seconds I kept my balance and pedaling. So I guess we can ride our bikes in our sleep.