error levels
You may need to differentiate between error levels - such as errors generated by a form, a 'no results returned' error, etc. vs. system or database errors.
Use a generic error handler to customize error handling. You can already control error handling through PHP, but you might want generic application-level error handling. My scripts use a lot of templating stuff, but something along the lines of:
functions.php
function s_error($msg='Undefined Error', $kill=false, $priority=3, $log=false)
{
switch($priority)
{
case 1: // Alert the troops
log_error($msg,$priority);
sound_the_alarms($msg);
die('We might not be back for a bit.');
case 2: // Unrecoverable system error
if($log) log_error($msg,$priority);
die('System Error: ' . $msg);
case 3: // User / general error
if($log) log_error($msg,$priority);
echo "Sorry, an error occurred: " . $msg;
break;
default: // Or however else you want to handle this by default
die('Unspecified error');
}
return false;
}
Obviously, a lot more can be done with this, like handling error codes, formatting user errors, sending messages off to your mobile, etc. I check for an array in $msg and list multiple errors through a templater for example.
This way you can handle unrecoverable errors, or just spit general errors back to the user:
if(!database_exists()) s_error("Our database has been stolen!",true,1,true);
if(!is_friendly($_POST['username'])) s_error("Sorry, you're mean!");