Re: Re: ErrorStack problems

From: Date: Fri, 01 Apr 2005 05:03:43 +0000
Subject: Re: Re: ErrorStack problems
References: 1 2  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-18459@lists.php.net to get a copy of this message
On 01/04/2005, at 2:29 PM, Greg Beaver wrote:
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':
change this to case 'PEAR_Error':
                // 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'));
cut the next two lines, and instead use:
$dbstack = &PEAR_ErrorStack::singleton('MDB2'); $dbstack->setDefaultCallback(array(&$myobj, 'errorCallback'));
PEAR_ErrorStack::setDefaultCallback(array(&$myobj, 'errorCallback');
I have made that change its still displaying Pear_Error as the package name not MB2 is that due to the Pear_Error callback method being changed ? I do however get the message being displayed, $err['code'] however returns nothing. With that example I am using, should I be doing something with displaying the error in the ErrorStack callback method directly it looks like its pushing the error back into the ErrorStack again for some odd reason ? It seems alot of work just for setting up a global error handler :|

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