Re: ErrorStack problems
| From: | Greg Beaver | Date: | Fri, 01 Apr 2005 04:29:02 +0000 |
| Subject: | Re: ErrorStack problems | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-18457@lists.php.net to get a copy of this message | ||
Dan Rossi wrote:
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':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 thiserror,// 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'); Greg