I'm having a similar issue but it's not "debug" code but rather a blank page and generic error msg is inserted AFTER the custom 404 message. Here's my custom code:
<div style="width: 200px; margin-left: auto; margin-right: auto;">Error 404 - {errormessage}
<p><strong>Please try the </strong>
<a href="http://{siteurl}/index.php" title="Home Page">Home Page</a> or
<a href="mailto:{sitemail}">contact</a> the System Administrator.</p>
</div>
Visit this page to get a 404 error and see the output:
atomvoyages.com/index.htm
Any ideas on what I did to my setup to cause this?