Re: Try Catch

From: Date: Sun, 22 Jul 2001 18:03:47 +0000
Subject: Re: Try Catch
References: 1 2 3 4 5 6 7 8  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-979@lists.php.net to get a copy of this message
"Stig S. Bakken" wrote: > > "Tomas V.V.Cox" wrote: > > > > "Stig S. Bakken" wrote: > > > > > > Oleg Rekutin wrote: > > > > > > > > > > That should be the case, I think. I would consider the current callback- > > > > related problem with nextID/createSequence a bug. > > > > > > Agreed. Will fix. > > > > > > > This problem could (and probably others in the future) solved having a > > way to differentiate if error objects should or not use selected error > > handler instead of PEAR_ERROR_RETURN. > > > > Some situations and posible solutions: > > > > * The user's point of view: > > > > //universal error handler > > PEAR::setErrorHandling() > > // per class handler > > $db->setErrorHandling() > > > > * The Pear developer point of view: > > > > 1) Classes that use other classes: > > class foo { > > function fooBar() { > > $db = new DB_Bar; > > // always must be present > > $db->setErrorHandling(PEAR_ERROR_RETURN); > > $this->db->query(); > > } > > } > > > > 2) Public methods calling private methods inside the same class: > > > > funtion do() { > > $error = $this->_query(); > > if (PEAR::isError($error)) { > > // raise the created error object > > return $this->raiseErrorObj($error); > > } > > } > > > > function _query() { > > if (!mysql_query()) { > > // never use raiseError > > return new PEAR_Error('fail!'); > > } > > } > > > > 3) Public methods calling public methods inside the same class: > > > > $this->errorHandlerDisable(); > > $error = $this->query(); > > $this->errorHandlerRestore(); > > if (PEAR::isError($error)) { > > $this->fooDelete(); > > return $this->raiseErrorObj($error); > > } > > > > More intelligent ideas? > > > > Tomas V.V.Cox > > > > PS.-method names are only for ilustrating the idea > > I think a more generic solution would be to make error handlers a stack, > so you can "push" and "pop" any number of temporary error handlers: > > class foo { > function fooBar() { > $db = new DB_Bar; > $db->pushErrorHandling(PEAR_ERROR_RETURN); > $db->query(...); > $db->popErrorHandling(); > } > } > Yeah, good idea, but still have one problem. Think for example in the nextID problem: $this->pushEH(RETURN); $err = $db->query(); $this->popEH(); do { [...] } while ($repeat): // at this time we return the error, but don't // do action as they ocurrs at object creation time if (DB::isError($err)) { return $err; } [...] We need an extra function to "re-trigger" errors, this is: do the actions with the data contained in the error. I though on: a new PEAR method for ex: raiseErrorObject($obj), but now I can imagine also a PEAR_Error::raiseError. 1) return $this->raiseErrorObject($err); 2) return $err->raiseError(); Clear not? :) Tomas V.V.Cox

« previous php.pear.dev (#979) next »