Error Handling, was: PEAR Status

From: Date: Sun, 25 Jun 2000 10:24:34 +0000
Subject: Error Handling, was: PEAR Status
References: 1 2 3 4  Groups: php.pear 
Request: Send a blank email to php-pear+get-122@lists.php.net to get a copy of this message
Sterling Hughes wrote: > > - error handling > > > > Why not through a pear error object with all necessary information: > > class PEAR_ERROR > { > var $errno; > var $errstr; > var $calling_package; > var $method; > } > > Then you can return from your method: > > class fubar > { > function foo ($args = array()) > { > if (count ($args) < 1) { > $ret = new PEAR_ERROR; > $ret->errno = WRONG_PARAM_COUNT; > $ret->errstr = "Wrong parameter count"; > $ret->calling_package = "fubar"; > $ret->method = "foo"; > return ($ret); > } > } > } No matter wich attempt you take an underlying limitation of PHP remains. You can do error handling the way Stig has done it in the DB package, you can take the old way with $error, $errno and setError(), halt() (see the PHPLib Core) or you can try the Java way (see the exception classes I placed in the PHPLib CVS (php/form/exceptions/)). None of these way gives you the final solution. Why? We can't distinguish between valid return values and error codes returned. There will always be collisions. What we really need is a new language construct: try { ... some code .. } catch ( name of exception ) { ... code handling the exception ... } I don't think we will get it in near future, so we gave to find some faulty compromise. Stig ways works fine with static classes, my attempt in the phplib cvs does not. Maybe someone has the time to join both ways and add the new error handling facilities of php4.01 to them ( set_error_handler(), trigger_error(), restore_error_handler() ). Ulf

« previous php.pear (#122) next »