News Feed
Sections




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

Michael Nitschinger's Blog:
A primer on PHP exceptions
May 23, 2012 @ 09:17:41

Michael Nitschinger has a new post focusing on one of the more commonly used, but maybe just as commonly misunderstood, part of PHP - exceptions and their handling. His latest post looks at what Exceptions in PHP have to offer and provides some "best practices" in their use.

Exceptions are and should be an integral part of any general purpose programming language. PHP introduced them long ago (with the release of PHP 5 or 5.1), but it still seems that many of the concepts are not fully understood or ignored by the community. This post aims to be a solid introduction to exception architecture, handling and testing. At the end of the post you should be able to know when to raise an exception and how it should look like.

He talks about situations when (and when not) to use exceptions, normalizing them for easier try/catch-ing and includes the exception class hierarchy, including the types pulled from the SPL. He shows examples (based on the Lithium framework's namespacing) how to create "namespaced exceptions" and how to use these in a bit of sample code. He also mentions the use of the custom error handling with the ErrorException as well as a quick look at testing these basic and custom exceptions correctly (PHPUnit-based tests).

0 comments voice your opinion now!
exception custom namespace tutorial primer unittest lithium


blog comments powered by Disqus

Similar Posts

PaperMashup.com: Easy PHP Pagination

SitePoint PHP Blog: Unit Testing with GuzzlePHP

HowTo Forge: Installing Lighttpd With PHP5 And MySQL Support On Mandriva 2008.0

Zend Developer Zone: AJAX Chat Tutorial Part 6 : Updating the User List

DZone.com: Video: PHP 5.3.1, MongoDB and Lithium on Windows 7 / IIS 7


Community Events

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


example php7 version voicesoftheelephpant conference opinion podcast community library interview symfony2 framework series laravel performance introduction api release extension install

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