How can I theme "Error generating image." error 500's in Drupal 7? I wish to theme the error pages generated by the image module in drupal 7, I'm not sure it can be done as this is the code that runs when imagecache fails to generate a style:

else {
    watchdog('image', 'Unable to generate the derived image located at %path.', array('%path' =&gt; $derivative_uri));
    drupal_add_http_header('Status', '500 Internal Server Error');
    print t('Error generating image.');
    drupal_exit();
}


I'm not intending on having a whole themed page, but something that isn't quite as ghastly as white screen with just "Error generating image." on it. Rather at least some way for a visiting to navigate away from it and remain on the site if they wish. It would be even better if I could return a 404 instead.

This is of course, without hacking core. So anyone have any ideas or have I missed something?
You can't.

This is hardcoded in http://api.drupal.org/api/drupal/modules--image--image.module/function/image_style_deliver/7.

You would need to completely override this page callback to change what it does. You could do this with hook_menu_alter() but that means that you would need to make sure that you also apply any upstream changes to that function to your own copy.

Can't you just leave the images there instead of deleting them? And if they are just a temporary resource, maybe exclude them from search with robots.txt?