News Feed
Sections




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

PHPMaster.com:
Exceptional Exceptions
November 16, 2012 @ 11:49:08

On PHPMaster.com today they have a new post from Remi Woler about "exceptional exceptions" - using exceptions to handle the flow of your application's execution a bit better.

Unlike errors, exceptions are designed to be handled by the calling code and will bubble up the execution chain until they are caught. Code in the current scope will stop executing as soon as an exception is thrown (so any lines after a throw statement won't be executed) and control is handed back to the first matching exception handler (either a catch block, configured exception handler, or language-provided exception handler). Only when an exception is caught will code execution continue from there. This article does not aim to teach you exceptions at a 101 level, but instead gives an opinion on how to use exceptions better

The post helps you determine the difference between an error and an exceptional event and gives examples of the sorts of things he considers exceptions useful for. He also talks about throwing different kinds of exceptions to make their context more meaningful, but notes that this has been known to cause trouble if used too much.

In summary, only throw exceptions when your code cannot complete the requested instruction with the given input, always throw a custom exception that actually tells the calling code what the situation is, and if you call other code then only catch the exceptions that you can and should handle.
0 comments voice your opinion now!
exception tutorial cases custom error catchall


blog comments powered by Disqus

Similar Posts

PHPMaster.com: Under the Hood of Yii’s Component Architecture, Part 2

Evolt.org: Working With Fractions In CSS and PHP

Zend Developer Zone: 2 Beginners Guides I Wish I had when I Started with PHP

ProDevTips Blog: Fluent Arrays and Strings in PHP - Adding JSON and more

DevShed: Creating AJAX Requester Objects with Abstract Factory Classes in PHP 5


Community Events





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


deployment laravel language list library opinion interview zendserver api community symfony install introduction framework tips release podcast package update series

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