Re: Proper error handling with DB_DataObject

From: Date: Thu, 29 Dec 2005 19:13:19 +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-22379@lists.php.net to get a copy of this message
Hi, Markus Wolff wrote:
Markus Fischer schrieb:
the documentation somehow lacks the information on how can I test a DB_DataObject if something went terrible wrong? But if update/insert for some reason fails, I'm not sure where my single point is to detect errors.
Put this at some central point in your app: PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'errorHandler'); function errorHandler($error) {
    // your handler code here, ex.:
    die($error->getMessage());
}
I've skipped the PHP5 part as I'm tied to PHP4 at this point. Is it only me or why do I find it so unnatural to define some global function to be called in case of errors? This may be 'the PHP way' but I don't feel very comfortable to suddenly break out of my control flow and continue in some handler when I need to return from the current control function. I'm in a specific situation and what to control what happens with an error in this case. Given your advice I would suddenly catch all PEAR errors when I just want to check if the last DataObject operation was successful; in place. For example, I'm in a remote called service and this method gets called: [...] function doSomething($aData) { require_once 'Other/Framework.php'; require 'Other/Framework/DataObjectGlobalConfig.php'; $oTable =& DB_DataObject::factory('table'); # first place where to check for errors if (PEAR::isError( $oTable )) {
    return new RpcError($oTable->getMessage());
} $oTable->someCol1 = $data[0]; $oTable->someCol2 = $data[1]; $oTable->someCol3 = $data[2]; $oTable->find(true); # how to properly check for any errors here now? # call a handler somewhere else?! } [...] Maybe this helps a bit understanding what I'm trying to achive. If now there is a find() or insert() call I need to check whether there was no error because it's critical to report the proper state back to me. Thanks for your time, - Markus

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