ErrorStack problems

From: Date: Fri, 01 Apr 2005 04:04:55 +0000
Subject: ErrorStack problems
Groups: php.pear.general 
Request: Send a blank email to pear-general+get-18455@lists.php.net to get a copy of this message
Hi there, I am having issues implementing the ErrorStack class, i have got up to combining the Pear_Error into the ErrorStack for classes that use it which is most of the ones I use :| I want to get MDB2 errors being triggered different to other packages, when i do a die($err['package'] ) its showing up PEAR_Error becauses thats what i put in the old Pear_Error callback function to ErrorStack. I dont really know where to go through here, it looks like all Pear_Errors's will have to be treated the same. How do I now use the errorCallBack method to spit out the error, page and line number and any other custom message ? I also want to see if I can make two versions of the display, one for debugging code which shows the full error stack, then a general error page for the end user which i can then choose to log and/or email me the error. Hmm it'll happen soon enough. class Error_Exceptions {
    var $_stack;
    function Error_Exceptions()
    {
        $this->_stack = &PEAR_ErrorStack::singleton('Project');
    }
    function errorStack($error)
{ PEAR_ErrorStack::staticPush('PEAR_Error',null,'error', array('olderror'=>$error),$error->getMessage().\n.$error-
getDebugInfo());
}
    function errorCallback($err)
    {
        switch($err['package']){
            case 'Project':
                // tell the error stack to log the error only
                // it will not be pushed onto the stack
                return PEAR_ERRORSTACK_LOG;
                break;
            case 'MDB2':
                // re-package these errors as a mypackage error fit
                // for enduser consumption
                $this->_stack->push(MYPACKAGE_ERROR_DBERROR, 'error',
                    array('dbmessage' => $err['message'],
                          'dbcode' => $err['code'],
                          'We are having Connection problems, please' .
                          'try again in a few moments'),
                    '', $err); // include the error as re-packaged
                // tell the internal DB error stack to ignore this
error,
                // as if it never happened
                return PEAR_ERRORSTACK_IGNORE;
                break;
        } // switch
    }
} $myobj = &new Error_Exceptions; PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array('Error_Exceptions', 'errorStack')); $dbstack = &PEAR_ErrorStack::singleton('MDB2'); $dbstack->setDefaultCallback(array(&$myobj, 'errorCallback'));

« previous php.pear.general (#18455) next »