Re: Try Catch
| From: | Andi Gutmans | Date: | Sat, 21 Jul 2001 01:21:33 +0000 |
| Subject: | Re: Try Catch | ||
| References: | 1 2 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-902@lists.php.net to get a copy of this message | ||
We are planning to add support for exceptions in the Zend Engine 2.
Andi
At 12:03 AM 7/21/2001 +0000, Oleg Rekutin wrote:
ed@belsoft.vitebsk.by (Ed V. Bartosh) wrote in news:858zhjqjet.fsf@bartosh.org: /Fri, 20 Jul 2001 15:55:51 -0700/ you wrote: RK> Do we have a Try Catch in PHP? RK> I'm tired ofRK> if ( PEAR::isError (No try/catch, no exceptions support, no goto to fudge it either. I've spent a long time trying to figure out how to emulate exceptions or alleviate the pain of if (PEAR::isError(, but failed to come up with a solution. If PHP had support for C++-like macros (so that 'return' in a macro ends the function in which macro was specified and not the macro itself, and so that the macro has the same symbol table as its 'user' function), and 'goto' or setjmp/longjmp kinds of operators, it would be possible to have basic exception support emulated. Use callbacks instead: PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, ... Callbacks are not enough because they are triggered when the error is first thrown and cannot alter the control flow. This means that the code cannot add extra information as the error 'bubbles up' (small concern, but still useful) or handle errors selectively (say DB raises one error that certain code can fix, but the rest of DB errors are lethal... with a general callback, once the error is thrown, the code that was able to fix the problem will not be reached). Perhaps that last point was unclear... Example, emulated MySQL sequences in PEAR DB. If sequence was never created, attempting to retrieve the next id results in a DB_Error thrown inside of DB_mysql::nextId(). However, nextId() checks whether the error is 'no such table' and if so, attempts to create the sequence, and then tries again to retrieve the next ID. If a callback is registered, then the execution will stop when nextId() fails to obtain the first ID, even though it knew how to recover. In my current application, I just made a keyboard shortcut for if (PEAR::isError($result)) return $result, which is what I do in almost all cases, with the exception of where I actually handle received errors. - Oleg -- PEAR Development Mailing List (http://pear.php.net/) To unsubscribe, e-mail: pear-dev-unsubscribe@lists.php.net For additional commands, e-mail: pear-dev-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net