PEAR::expectError
| From: | (Stig Sæther Bakken) | Date: | Tue, 14 Aug 2001 13:11:17 +0000 |
| Subject: | PEAR::expectError | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-1477@lists.php.net to get a copy of this message | ||
Hi,
Have you ever had an error callback function, but you needed to check
if a DB query returned just a specific error?
Here's a suggestion:
$dbh->expectError(DB_ERROR_SYNTAX);
$err = $dbh->query("BAD QUERY");
if (DB::isError($err) && $err->getCode() == DB_ERROR_SYNTAX) {
print "it works!";
}
Check out the PEAR class from CVS to test it. I have told myself to
not start implementing much more error-handling magic until Zend 2.0
appears, but this one wanted out very badly. The thing that's missing
from it now is stacking, so you can push and pop expected errors.
expectError is limited to the object(s) to apply it to, it would be
very useful if aggregated objects had a way of "inheriting" it.
- Stig
--
Stig Sæther Bakken <ssb@alltheweb.com>
Fast Search & Transfer ASA, Trondheim, Norway