Re: Re: ErrorStack problems

From: Date: Fri, 01 Apr 2005 05:13:46 +0000
Subject: Re: Re: ErrorStack problems
References: 1 2 3  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-18460@lists.php.net to get a copy of this message
Dan Rossi wrote:
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 :|
Nah, the work is in understanding your assumptions and how they differ from the way PEAR_ErrorStack works, as with any new software. Are you using PEAR_ErrorStack for any reason other than handling PEAR_Error? If not, then why not simply use a PEAR_Error callback? PEAR_ErrorStack is designed to make combining code that uses different error handling systems easy, as well as to be used for new projects from scratch. Using it to handle PEAR_Error on its own for no other reason is just going to be awkward. In any case, try this code: <?php class Error_Exceptions { var $_stack; function Error_Exceptions() {
       $this->_stack = &PEAR_ErrorStack::singleton('Project');
} function errorStack($error) {
       PEAR_ErrorStack::staticPush('MDB2',$error->getCode(),'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')); PEAR_ErrorStack::setDefaultCallback(array(&$myobj, 'errorCallback')); ?> Greg

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