Re: Re: Making PEAR_ErrorStack throw PHP5 exceptions
| From: | Greg Beaver | Date: | Mon, 22 Nov 2004 14:56:09 +0000 |
| Subject: | Re: Re: Making PEAR_ErrorStack throw PHP5 exceptions | ||
| References: | 1 2 3 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-15755@lists.php.net to get a copy of this message | ||
Jeroen Houben wrote:
Hi Greg, Greg Beaver wrote:Yes it will. Even better than my original suggestion would be $db = DB::factory('whatever'); $db->setErrorHandling(PEAR_ERROR_CALLBACK, 'catchPEAR'); GregOf course, you can customize the DBException to include the original PEAR_Error object if you would like. However, far simpler for your purposes is to simply use a PEAR_Error callback <?php require_once 'PEAR.php'; PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'catchPEAR'); class DBException extends Exception {} function catchPEAR($err) {Will this turn all PEAR errors into Exceptions? What if I just wanted to repackage PEAR::DB errors? Can I safely do DB::setErrorHandling(PEAR_ERROR_CALLBACK, 'catchPEAR'); ??throw new DBException($err->getMessage(), $err->getCode();} ?>