View Single Post
Old 11-13-2012, 04:41 AM   PM User | #10
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,650
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
. . .no. . . more. . . code. Lol
Error handling is exceedingly easy to perform. Since you have specific criteria, that is what I would suggest passing to the trigger.
PHP Code:
function errorHandler($errno$errstr$errfile$errline)
{
    
$_SESSION['resultsCode'] = $errstr;
    switch (
$errno)
    {
        case 
E_USER_FATAL:
            
// email or whatever.  I'd die here
            
die();
        default:
            
header('Location: ' ERROR_LOCATION);
            die();
    }
    return 
true;
}

set_error_handler('errorHandler'E_USER_NOTICE E_USER_WARNING E_USER_FATAL);

if (
$badDataIsTrue)
{
    
trigger_error('COMMENT_MEMBER_COMMENT_FAILED_2053'E_USER_WARNING);

Now you simply define ERROR_LOCATION on a script by script basis, and when triggered the error handler will assign the given value to the session, and redirect to the location under ERROR_LOCATION.
You are bound by only using the three error levels on a trigger. Technically you could take an E_USER_NOTICE level and assign results this way and modify the error handler to react accordingly. Personally I wouldn't do that, I'd just continue processing per normal for good runs, and present the error handler with failures only. I'd suggest that E_USER_FATAL is the only one you need to do something like issue an email, but the others may want to have a logging feature in place or whatever.
Fou-Lu is offline   Reply With Quote