News Feed
Sections




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

Slawek Lukasiewicz's Blog:
Throwing Exception with Type Hinting Failed
August 10, 2011 @ 09:58:57

Slawek Lukasiewicz has a helpful hint posted to his blog today about handling type hinting failures in a what he sees as a "more correct" way than just throwing an error - throwing an exception when the hinting criteria's not met.

One of the most annoying behavior of PHP type hinting feature is triggering error instead of throwing exception when instance type is invalid.

By default, a failure generates a "catchable error" that, thanks to the custom error handling methods PHP includes, can be correctly handled. He includes a snippet of code that defines the errorHandler method that checks the error type for E_RECOVERABLE_ERROR and throws the exception (an ErrorException) if found.

0 comments voice your opinion now!
typehinting exception failure catchable error handling custom


blog comments powered by Disqus

Similar Posts

NPR.org: Building the Ingest System

SitePoint PHP Blog: How to Make WordPress Easier for Clients, Part 1: Custom Branding

Christopher Kunz's Blog: Warning about the article "SQL Injection" in current "PHP Magazin"

Derick Rethans' Blog: Five reasons why the shut-op operator (@) should be avoided

Slawek Lukasiewicz's Blog: Throwing Exception with Type Hinting Failed


Community Events





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


conference library release voicesoftheelephpant laravel tool version community symfony framework language introduction list podcast series interview composer opinion artisanfiles security

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