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

Dallas PHP User Group: PHP5 & LAMP Classes at North Lake College

Lorna Mitchell's Blog: PHP REST Server (Part 2 of 3)

DevShed: A MIME Mailer Class

NETTUTS.com: A Better Login System

Nikita Popov: Are PHP developers functophobic?


Community Events





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


voicesoftheelephpant opinion introduction package unittest zendserver series api release language framework install library deployment symfony laravel bugfix interview community podcast

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