Re: ErrorStack
| From: | greg at chiaraquartet dot net | Date: | Sat, 05 Feb 2005 15:20:54 +0000 |
| Subject: | Re: ErrorStack | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-35961@lists.php.net to get a copy of this message | ||
Lukas Smith wrote:
> Hi Greg,
>
> I am having trouble figureing out the equivalent to
> expectError()/popExpectError() in ErrorStack.
>
> Specifically I want to know how I can disable global error handlers
> locally.
>
> regards,
> Lukas
Hi Lukas,
I'm out of town, and there is some weird firewall preventing all access to SMTP
servers (stupid "security"), so I'm forced to use a web interface to do this.
ErrorStack is structured around callbacks. If you want to temporarily override
callbacks, use pushCallback()/popCallback() to pass in a callback that simply
returns PEAR_ERRORSTACK_IGNORE.
If you wish to ignore only particular errors, then you would basically implement
expectError() as a callback. I didn't implement expectError directly in
ErrorStack because a very small minority of projects actually need it, and it's
only about 12 lines of code.
var $_expectedErrors = array();
function expectErrors($errs)
{
$this->_expectedErrors = is_array($errs) ? $errs : array($errs);
}
function expectCallback($err)
{
if (in_array($err['code'], $this->_expectedErrors)) {
return PEAR_ERRORSTACK_IGNORE; // or PEAR_ERRORSTACK_LOG, etc.
}
else return PEAR_ERRORSTACK_PUSHANDLOG;
}
...
then, later:
$this->expectErrors(MDB2_SOMETHING);
$this->_stack->pushCallback(array(&$this, 'expectCallback'));
blablah;
$this->_stack->popCallback();
if ($this->_stack->hasErrors()) {
....
}
Greg