Re: PEAR: error handling in classes

From: Date: Mon, 18 Mar 2002 20:51:11 +0000
Subject: Re: PEAR: error handling in classes
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-980@lists.php.net to get a copy of this message
Maxim, 21:36:18 18. marec 2002 (pondelok) Greets. Thank you for your answers. > Well, I haven't really tested that but should work :-) If you don't have > in your class an error handler just check each DB operation that could > return an error object in case of fail and return it as a error string or > false. Would not be better to return PEAR Error object from PEAR compliant class? Look, DB is a PEAR compliant class and it returns PEAR Error object on error. I think also another PEAR classes should return it the same. Wrong idea? Next problem belong to catching expected error. The first possibility seems to be good and it also worked. The second has IMHO a little problem. > 2) Temporary change the actual error handler: > > $db->pushErrorHandling(PEAR_ERROR_RETURN); > $res = $db->query("INSERT INTO .."); > $db->popErrorHandling(); > > To rest of the code for both cases could be: > if (DB::isError($res) && $res->getCode() == DB_ERROR_ALREADY_EXISTS) { > // the expected error > } I think this will not perfectly work. I set error handling to PEAR_ERROR_RETURN, but if someone has set PEAR Error handler, it will be not called on query failure. It is desirable if it will be not called on DB_ERROR_ALREADY_EXISTS, but it will be not called also on other errors. And that seems to be bad. I hope you understand me. All what is needed in this part of code to be added is something what will cause error handler to run if returned error is not expected. Something like this: $db->pushErrorHandling(PEAR_ERROR_RETURN); $res = $db->query("INSERT INTO .."); $db->popErrorHandling(); if (DB::isError($res)) { if ($res->getCode() == DB_ERROR_ALREADY_EXISTS) { // the expected error } else { // This is another error which is not expected // so we must raise it. // NOTE: this is only tip how it could be PEAR::raiseError($res); } } I'm right or absolutely mismatch? Thanks. =Nepto= ____________________________________________________________________________ Ondrej 'Nepto' Jombik, absolutely QT free http://www.gtk.org

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