Re: DB_DataObject error handling
| From: | Markus Fischer | Date: | Mon, 21 Aug 2006 16:39:50 +0000 |
| Subject: | Re: DB_DataObject error handling | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-24928@lists.php.net to get a copy of this message | ||
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Jeff Loiselle wrote:
> What's the reccomended method for capturing the ubiqitous:
> "DB_DataObject Error: Connect failed, turn on debugging to 5 see why"
>
> I've tried:
> $do->setErrorHandling().. but I can't seem to get it to work.
>
> I never want the user to see this. I want them to see vast pretty
> fields filled with opium plants. instead.
I don't know if this handles your specific case but I was quite happy
with the solution I found: i just overloaded raiseError() and did
appropriate action according to my environment:
public function raiseError($sMessage, $iErrorCode = 0, $iBehaviour =
PEAR_ERROR_RETURN) {
if (PEAR::isError($sMessage)) {
throw new Tsf_PEAR_DB_DataObject_Exception($sMessage->getMessage(),
$iErrorCode, $sMessage);
} else {
throw new Tsf_PEAR_DB_DataObject_Exception($sMessage, $iErrorCode);
}
}
However note that this requires creating a separate new class, in my
case Tsf_PEAR_DB_DataObject and you need to configure the table creation
script so all generated classes extend from your new class. In my case
this was the only viable solution I found with which I could live here.
Another error I needed to handle was the factory method:
public function factory($table = '') {
$oRet = parent::factory($table);
if (PEAR::isError($oRet)) {
Tsf_PEAR_DB_DataObject::raiseError($oRet);
}
return $oRet;
}
This, too, requires that you factor all classes from your new class and
not from DB_DataObject. This is basically what I'm doing all the time now.
- - Markus
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFE6eHW1nS0RcInK9ARAhbxAJ9Wl+L8LpWhQF3FzCYQ69f5cQ84mQCg4M3h
GbMH1l4T7JTpMFOByemBQ+c=
=O0Cj
-----END PGP SIGNATURE-----