Re: PEAR::expectError

From: Date: Tue, 14 Aug 2001 15:23:32 +0000
Subject: Re: PEAR::expectError
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-1478@lists.php.net to get a copy of this message
Stig Sæther Bakken wrote: > > Hi, > > Have you ever had an error callback function, but you needed to check > if a DB query returned just a specific error? nextID for example? :) > 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!"; > } Umm... sorry but I don't undestand that very well. expectError() disables the actual error handling, ok, but what is supposed to be the pourpose of the error code you give to the function? In your example I don't see also when you restore the error handler, may be before raise the error? Isn't that equivalent to pop/push error handlers? > 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. Perhaps we could simplify things (at least pop/push) and do all only with setErrorHandling. For example: // push a new mode $db->setErrorHandling($mode); $err = $db->query(); // pop if no args $db->setErrorHandling(); Tomas V.V.Cox

« previous php.pear.dev (#1478) next »