Not sure about xp (i presume it's the same though) but in 2k3 on the database (battle layout i think can't quite remember; look for it) there's an handler for random encouter death situations. You can set it to just game over (as is default) or execute custom handler and it also gives the option to teleport somewhere first as well.
You can also set this up in forced encouters such as bosses, you get the option in the event menu when you select 'enemy encouter'.