Redirect to last page visited on 404 error
There's a module for that: CustomError, which has a development snapshot for Drupal 7.


  This module allows the site admin to create custom error pages for 404 (not found), and 403 (access denied), without the need to create nodes for each of them.
  
  Since the error pages are not real nodes, they do not belong a category term, they do not show in the search, and will not show up in node listings, or in Popular Content block.