This is the sort of subject I would definitely cover before gaming with a group. Some players are blase about losing a character and merely reach for the dice to roll up a new one, while others treat their characters better than their spouses and might stomp away from the table in disgust if they lost one.
Let your players know your feelings on this (hard and fast, if you're dead, your'e dead; or, more lenient, you have a chance to survive no matter what the dice say) and stick to it. Nothing worse, not even a TPK, than a DM or gamemaster that won't keep his word.
If the danger of the situation has been relayed appropriately (this is the lair of a dragon that has killed 100 adventurers), and your party is relatively powerful and with many resources, you should really let the chips fall where they may. Constantly "letting" players win, ignoring or forgiving dumb mistakes (rushing a demon lord with 1 hp and a dagger), never letting players face foes beyond their capability (would Darth Vader be the villain he was if he was only as powerful as the rest of the Star Wars gang?), or constantly pulling them out of trouble with Deus Ex Machina is really just enabling bad habits of your players, and not letting them experience the full richness of the gaming experience. Some of the greatest flicks of all time (The Seven Samurai, The Magnificent Seven, The Wild Bunch, The Dirty Dozen, Butch Cassidy and the Sundance Kid) end up with either a TPK or something pretty close to it, and yet these are regarded as some of the greatest films ever made. There is something about a "grand gesture" that ends in death that is timeless in culture. Encourage the same feeling in your players should this happen to them, saying their deaths will be extolled by bards and their sad tale told around campfires for decades to come (especially if their end was at the hands of some superior foe like a dragon or demonic being), inspiring new heroes!
If you have a TPK and for some reason you, the players, or both you and the players don't want it to end like that, there are several ways to work around a final ending for the characters:
In a fantasy world, being raised from the dead is not out of the question. Have a high level priest or mage find the dead characters, have them raised, then have the PCs serve their savior for awhile to pay him back. Perhaps he has brought them back for a specific mission he wants them to perform....that could mean their death (again!)...
Whoever has destroyed the party may have an enemy other than the PCs, who would be loathe to see his rival get away unscathed. This being (who may be evil!) arranges to have the characters raised and, behind the scenes, puts them back on the trail of their killer(s) with additional powerful magic items. Imagine the roleplaying possiblities when the party finally realizes they have been raised by a creature just as bad as the one that killed them, and they have been doing his dirty work for him!
After the final body has fallen, the next session have the characters wake up in some desolate locale, alive but confused at how they got there. It could be a tropical isle or a frozen waste, and lots of adventures await them surviving and getting back to their own lands. If they do any investigating of how they could have possibly survived, have them discover (through research or spells) that a non-descript ring worn by one character was actually a special ring of wishes, with one wish, whose power was subconsiously activated when the character died to bring himself and his allies back to life in a "safe" place. This is a good hook if you want to completely change up the campaign feel and perhaps take away some magic or items you didn't like your players having (trade off for having come back to life...maybe they wake up nude in the distant clime with nothing but their mind and body to help them survive!)
If your players are the type that are up for a bit of roleplaying and a real challenge, have them wake up in a dirty cell, having been raised, jailed, and enslaved by their foe! Gloating at them through the bars of their new home, he tells them they will slave away in the mines (mines are always good, being below the earth!) until they die and then he will raise them again and again...what's the point of them dying when he can torture them forever? This can lead to some great roleplaying and ingenuity as the players try to work out their best "Escape from Alcatraz" scenarios attempting to get their items back and get the heck outta there. They aren't dead, but they may wish they were!
A mundane solution is to have the next party consist of family, friends, hirelings, henchmen and employees of the first group, all banded together to find out what really happened to "Party X" who disappeared many years before. There is a connection to the first party, and as an added bonus, if/when they find the remains of their family/friends, they can get all the magical goodies that have lain there for years untouched! Have the original villain come around to challenge the PCs, so they can get in a bit of revenge eventually.
Most of all, whatever you do, make sure you all are having fun and everyone is ok with what is going down. You might be surprised at how many players are ok with a TPK as long as everything was fair and above board.