How to handle pdo exception error gracefully for user experience
What? ... add a custom FAPI validator to your forms so there is no out-of-range error.

You could build on, or start off by using:
http://api.drupal.org/api/drupal/includes%21form.inc/function/element_validate_integer/7