News Feed
Sections




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

Jani Hartikainen's Blog:
Should a failed function return a value or throw an exception?
March 12, 2010 @ 10:41:43

Jani Hartikainen poses an interesting question on his blog today - is it more correct for a function, having failed at its job, to return a value of throw an exception.

You have created a nice, well written function, but you realize you forgot something: The failure case. What should a function do when it fails? There are two schools for this - the "throw an exception" school and the "return an error value" school. But which of these is the correct approach?

He suggests that this debate has stuck around from the time when there weren't exceptions in several popular programming languages and that returning the value was the only valid way. He touches on what an exception condition is (with a few code examples) and situations where each choice might be the right way to go.

1 comment voice your opinion now!
function return exception opinion


blog comments powered by Disqus

Similar Posts

I Am Learning PHP Blog: Do Web-Scripting Languages Really Need OOP?

Michael Babker's Blog: The Death of Joomla! - Negative Attitudes & Closed Minded Leadership

Zend Developer Zone: Accessing DB2 Data Inside of i5/OS

Reddit.com: Let's Make PHP's Function Names Consistent!

Vexxhost.com: Top 5 new (and cool!) features in PHP5 that you probably haven't heard of


Community Events





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


release language podcast community version interview security laravel series install framework update composer voicesoftheelephpant package introduction library tool symfony opinion

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