On Fri, 2003-09-05 at 17:42, George Schlossnagle wrote: > On Friday, September 5, 2003, at 11:30 AM, Sebastian Bergmann wrote: > > > Marcus Börger wrote: > >> try { > >> // code > >> } > >> catch (class1 $var) { > >> } > >> catch (class2 $var) { > >> } > >> catch ($var) { > >> } > > > > I thought that only objects of the Exception class and subclasses > > thereof can be throw(). > > > > Forcing all thrown objects to be subclassed from Exception does not > feel very PHP-ish.
Indeed. In fact, Exception is not even meant for this purpose, Marcus is talking about a different construct (although perhaps he wants the same functionality as the Exception class provides). Having a base Exception class provides a gentleman's catch-all. This means you can throw errors that explicitly bypass the catch-all exception. This is useful for example if we decided to throw "InternalException" which would be an exception thrown by PHP internal functions. InternalException could only be explicitly caught, and you could still allow for generic exception handling through the Exception base class... In general all classes should respect exception (which, btw, is why we should stick with studlyCaps naming - compatibility with PEAR), except for when you need to explicitly avoid the catch all. I don't think adding a generic catch is a good thing, it will lead to spaghetti code, and a large WTF factor when dealing with libraries that take advantage of the fact that the Base Exception class is not a catch-all :: end-all. -Sterling -- The most effective debugging tool is still careful thought, coupled with judiciously placed print statements. - Brian W Kernighan, 1978 -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php