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

Chris Cassell's Blog: Creating Magic Methods in PHP

Vance Lucas: Handling Exceptions in Gearman Tasks (Even Background Ones)

DevShed: Manipulating String Literals with Interpreter Classes in PHP 5

DevShed: Introducing the Strategy Pattern

NetTuts.com: How to Work with PHP and FTP


Community Events





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


install laravel version opinion interview voicesoftheelephpant language configure series conference list composer extension podcast symfony introduction community api unittest release

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