News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Rob Allen's Blog:
On Exceptions
September 08, 2010 @ 11:06:03

Rob Allen caught an interesting feature of the proposed exception handling in the Zend Framework v2 - the ability to throw an exception and catch it at the interface level, not just the class.

I've been reading the Proposal for Exceptions in ZF2 and like it. One thing that caught my attention was that it suggests that you can catch an interface. I hadn't heard of that ability before, so I pulled out my trusty text editor to have a play.

He creates a basic bit of code - an interface for the exceptions, an SPL exception class and a normal exceptions class - as well as a basic generic class that throws exceptions based on each. The result is that catching exceptions for the class types works as well as catching it on the "ExceptionInterface" level too.

We now have the ability with ZF2 to be able to use different exception classes to represent different error types rather than using string comparison and, at the same time, we can have a single catch() for when we don't need that level of granularity.
0 comments voice your opinion now!
exception handling interface throw class


blog comments powered by Disqus

Similar Posts

ThinkPHP Blog: Spooky Action at not so much Distance

Brandon Savage's Blog: Why Interfaces Rock

Mike\'s Blog: s/fluent/decorated

PHPClasses.org: Software Review - Delphi for PHP 2007

Till Klampaeckel's Blog: Tracking PHP errors


Community Events

Don't see your event here?
Let us know!


unittest interview release extension community library series api laravel5 php7 introduction opinion version framework voicesoftheelephpant podcast security development laravel language

All content copyright, 2015 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework