Re: Proper error handling with DB_DataObject

From: Date: Sat, 31 Dec 2005 06:55:55 +0000
Subject: Re: Proper error handling with DB_DataObject
References: 1 2  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-22398@lists.php.net to get a copy of this message
Alan Knowles wrote:
|From the comments in the source /** * Theses are the standard error codes, most methods will fail silently - and return false * to access the error message either use $table->_lastError * or $last_error = PEAR::getStaticProperty('DB_DataObject','lastError'); * the code is $last_error->code, and the message is $last_error->message (a standard PEAR error) */ This does deserve a bug report noting missing documentation though..
I will do :) So the real way is to either do if (strlen($DO->_lastError) > 0) { or if (PEAR::isError( $last_error = PEAR::getStaticProperty('DB_DataObject','lastError'))) { and if I want to further work with the$DO I have to set the _lastError to an emptry string and clear the static property.
If you need to expect errors - make sure you clear the _lastError value before calling the thing you know that might fail. - most methods should return false if they fail, otherwise it's probably a bug....
This this 'clearing' also affect the getStaticProperty call? How would I clear it? Just setting it with 'NULL' I don't want to challenge any architectical decisions about DB_DataObject (I think DO is superior to most other things out there) but the proper handling of error situations is very wierd in DO compared to other projects ... I mean, yes it makes do some degree sense to always return the value of a method regardless of an error, but for fine graned error handling it's also much easier to return a PEAR_Error for example. thanks, - Markus

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