News Feed
Jobs 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

Sameer Borate's Blog: Reading Google Analytics data from PHP

PHPClasses.org: Software Review - Delphi for PHP 2007

DevShed: Improving Exception Throwing when Auto Loading Classes in PHP 5

Cesarodas.com: gCache: Helping PHP to work faster

Jani Hartikainen's Blog: Exceptions and abstraction


Community Events











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


package component security threedevsandamaybe hhvm application composer framework facebook unittest database language introduction code symfony2 release install hack podcast performance

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