Re: [ZEND-ENGINE-CVS] cvs: ZendEngine2 / zend_default_classes.c zend_default_classes.h zend_execute.h zend_execute_API.c
| From: | Adam Maccabee Trachtenberg | Date: | Fri, 13 Feb 2004 16:35:08 +0000 |
| Subject: | Re: [ZEND-ENGINE-CVS] cvs: ZendEngine2 / zend_default_classes.c zend_default_classes.h zend_execute.h zend_execute_API.c | ||
| References: | 1 2 3 4 | Groups: | php.zend-engine.cvs |
| Request: | Send a blank email to php-zend-engine-cvs+get-2377@lists.php.net to get a copy of this message | ||
On Fri, 13 Feb 2004, George Schlossnagle wrote:
> On Feb 13, 2004, at 8:39 AM, Andi Gutmans wrote:
>
> > At 08:12 AM 2/13/2004 -0500, Sterling Hughes wrote:
> >> What is the reasoning for this new change?
> >
> > The reasoning is that it allows users to do a catch-all (which
> > otherwise we'd add to the language syntax). It also adds cleanliness
> > to the Exception hierarchy and allows PHP code to interact with PHP
> > code which isn't written by the developer knowing that there's a
> > common interface (such as getMessage()) which the exception always
> > adheres to. That improves the ability of exception handling especially
> > debugging and logging significantly.
>
> The above description sounds more like a 'best practice' and less like
> something that PHP should be forcing on users. If I explicitly choose
> to create an exception that must be caught specifically, I don't see
> why I shouldn't be allowed to do that.
You can still do:
class MyException extends Exception {}
try {
throw new MyException;
} catch (MyException $e) {
// handle specific exception
} catch (Exception $e) {
// catch all remaining generic exceptions
// aka "finally"
}
So I don't really see what's wrong with making all exceptions extend
the base Exception class.
Andi's point, I believe, is that otherwise we'll need to add a
"finally" keyword to make sure some random extension doesn't throw
some random undocumented exception that you could miss. And I agree
with him. It just seems to make everything more clean.
-adam
--
adam@trachtenberg.com
author of o'reilly's php cookbook
avoid the holiday rush, buy your copy today!