This is a list of things you probably shouldn't do on a regular basis. But if you're about to die, you might resort to them as a last-ditch defense against a one-way ticket on the Charon Express.
The most important thing to remember is: Don't Panic. Or at least, panic at your leisure. Nethack is not Quake. You have as much time as you want to think between each keypress. Stop, stretch, look at your situation, review your inventory (unless you are stuck in lava), and make a plan of action. Avoid the forehead slap of reviewing your post-mortem inventory and discovering something that would have saved your life.
Take a moment to learn a lesson and to remember it, even if you don't die. Look at the strategic, not the tactical reasons for your troubles. You don't die because of a soldier ant, you die because you are slowly crawling around burdened with junk, and wearing bad armor instead of pet-testing what you find. It really does help to keep book about your deaths.
There are a couple semi-routine moves you might consider first:
- Would engraving Elbereth help your situation? Of course, unless whatever's bashing you might not respect Elbereth. However, many an adventurer's life has been saved by repeatedly engraving Elbereth and resting on it.
- Pray. Your God may increase your hit points.
- Perhaps an escape item would help.
- Wizmode-test to determine the best strategy if you really care about this character.
Roughly in order of desperation:
- Perhaps you can dig down and drop to a lower level. Of course, the frying pan/fire potential is obvious. (This will not work with followers.)
- Polymorph yourself (ring, trap, wand, etc.). This will give you a fresh set of hit points. Once those have been burned through, you will revert to your original form (and your original hit points, so be careful).
- Polymorph whatever's bashing on you. This might not improve your situation.
- Break a wand. Wands of teleportation are great for this, particularly on no-teleport levels. If you're magic resistant, you should survive the magical blast from most wands, but with luck, the monsters around you might not.
- Eat a corpse that inflicts teleportitis. With luck, you'll teleport soon. Then of course, you have a new problem, but hopefully one much less severe.
- Read an unidentified scroll or book. You might read the book, have a wrenching sensation, and wind up on the other side of the level. On the other hand, you might read a scroll and make things worse.
- Read a book that is known to be cursed for a better chance at a teleportation - and a better chance at being blinded and paralyzed for hundreds of turns. Low-level books can only teleport you, so a cursed level one spellbook is an escape item.
- Drink from a sink. One possibility is drinking from a random, uncursed potion, which could be a healing potion, or you might polymorph. Then again, you might summon a water elemental or a sewer rat.
- Quaff an unidentified potion. It might be a potion of full healing. Of course, it might also be a potion of paralysis.
- Put on an unidentified amulet. Maybe you'll get an amulet of life saving. Maybe you'll get an amulet of strangulation
- Zap a wand that is out of charges. You have a 1 in 121 chance of getting another, final charge out of it.
If, after reviewing all of the options and you have utterly determined that you are going to perish, and are on an eligible bones level, you might consider [E]ngraving (quickly) a message of warning for other adventurers - the monster that killed you may move away when they enter the level and stumble upon your loot, but they at least may have a fighting chance. Additionally, although it is considered cheating, you can Engrave the highlights of your inventory (you have a bag of holding, or a single particular spellbook or other interesting item). The short length of space available to Engrave is a mild deterrent to this.
You may also consider dropping your best equipment--artifacts, a bag of holding, spellbooks, holy water, and wands. This will leave them in a pile of uncursed equipment for the benefit of future adventurers should a bones file be generated.