IIRC you have to survive to use it. However, there is a late-3e series of "resurrect mahself" cleric spells that you cast in advance.
Yes, I had that in my last campaign for the BBEG, who was also the high priest of the god of tyranny & slavery. I believe it cost a permanent 2 points of CON, however, that cannot be restored even through Wish/Miracle.
He had that cast on himself by one of his clerics who wished to curry his favor. (The way the deity was written up, there were two clerics that were second in command within the religion... one was a frail old woman, and the other was the epitome of female beauty in the mortal world. I figured the only way the old woman could compete for leadership against the young beauty was to offer up 2 points of CON to cast the contingent resurrection on her leader. And, thus, that was the story behind why she was not only old, but frail, but got to be the #2 cleric in the church.)
So, in the final encounter, the players were battered & bruised and finally managed to trap the high priest within an anti-magic shell. Without his magical defenses/buffs, they beat him down and chopped off his head in order to hopefully get the Dark Crown off of his now severed head (The Dark Crown was a powerful evil artifact).
I forgot what the next plan was for the PCs, but as soon as the head left the anti-magic field - Boom, the cleric springs back to life, fully healed. Wasn't that a surprise? (I think they hated me when that happened... ) However, since his body was back within the anti-magic shell still, the high cleric came back naked and without any weapons. Still, he managed to rally his troops and extend the battle for a while longer... and, with all the dead bodies on the battlefield, finding a weapon wasn't hard for him.