-- takeshin <[email protected]> wrote
(on Friday, 10 September 2010, 02:59 PM -0700):
> 
> Some thoughts about subclassing Exceptions:
> 
> http://stackoverflow.com/questions/3549836/subclassing-exceptions

In that post, you seem focussed on the idea of these being "ghost"
classes -- classes with no implementation, or marker interfaces.
Frankly, you're missing the point.

In ZF1, the Exception classes are component level only, and all
exceptions at that level receive the same exception class. This really
only allows the following types of catches:

 * Global level (catch "Exception")
 * Component level (catch component-level exception)

This is only slightly better than simply throwing "Exception"
everywhere; you need to carefully examine the exception messages to get
an idea of what went wrong.

Now, go and read the proposal carefully. 

The point of the proposal is to allow additional levels of granularity in
catching exceptions:

 * Don't care what exception it is? Catch \Exception.
 * Looking for exceptions from a specific component, but don't care
   about the specifics beyond that? Catch that component's Exception
   interface.
 * Want to look for specific types of SPL exception? Catch on those (in
   ZF2, exception classes implement the component exception interface,
   and extend appropriate SPL exceptions).
 * Want to catch a specific exception type within the component? Just
   catch it.

Basically, we allow for a greater amount of granularity just on the
exception _TYPE_ now; you would only need to check the message if there
are multiple exceptions of the same type that could be thrown by the
operation you're trying. Typically, this shouldn't be the case.

The SPL exceptions are fairly rich semantically, and many exceptions
within ZF would be better categorized as these types (e.g., invalid
arguments should raise an InvalidArgumentException; inability to resolve
a plugin would be a good RuntimeException; etc.). With ZF1, this isn't
possible -- we have to inherit from the component level exception,
period. By moving to a marker interface, we get both the ability to
catch component-level exceptions as well as the SPL-level -- and also on
a more specific exception type.

-- 
Matthew Weier O'Phinney
Project Lead            | [email protected]
Zend Framework          | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc

Reply via email to