The die() function, will always print out exactly what text you pass it. The way for you will be to create a function that returns the error message and then call the exit function.
function die_nicely($msg) {
echo <<<END
<div id="critical_error">$msg</div>
END;
exit;
}
I hope this helps you.