<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.3.1" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>
<channel>
	<title>Comments for CodeUtopia - The blog of Jani Hartikainen</title>
	<link>http://codeutopia.net/blog</link>
	<description>Software development with a focus on web-related technologies</description>
	<pubDate>Tue, 16 Mar 2010 05:13:13 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.1</generator>
		<item>
		<title>Comment on How much would you pay for good headphones? by Jean</title>
		<link>http://codeutopia.net/blog/2010/01/14/how-much-would-you-pay-for-good-headphones/#comment-55372</link>
		<dc:creator>Jean</dc:creator>
		<pubDate>Mon, 15 Mar 2010 21:44:25 +0000</pubDate>
		<guid>http://codeutopia.net/blog/2010/01/14/how-much-would-you-pay-for-good-headphones/#comment-55372</guid>
		<description>I've got a Sony MDR-V700 which I got for ~EUR120. Best damn headphones I've ever owned!</description>
		<content:encoded><![CDATA[<p>I&#8217;ve got a Sony MDR-V700 which I got for ~EUR120. Best damn headphones I&#8217;ve ever owned!</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Should a failed function return a value or throw an exception? by Jani Hartikainen</title>
		<link>http://codeutopia.net/blog/2010/03/11/should-a-failed-function-return-a-value-or-throw-an-exception/#comment-55252</link>
		<dc:creator>Jani Hartikainen</dc:creator>
		<pubDate>Sun, 14 Mar 2010 15:41:03 +0000</pubDate>
		<guid>http://codeutopia.net/blog/2010/03/11/should-a-failed-function-return-a-value-or-throw-an-exception/#comment-55252</guid>
		<description>Thanks for your comments all.

David, good point about the null object there. I've actually written about them here before, see http://codeutopia.net/blog/2009/09/12/what-is-a-null-object-and-when-are-they-useful/</description>
		<content:encoded><![CDATA[<p>Thanks for your comments all.</p>
<p>David, good point about the null object there. I&#8217;ve actually written about them here before, see <a href="http://codeutopia.net/blog/2009/09/12/what-is-a-null-object-and-when-are-they-useful/" rel="nofollow">http://codeutopia.net/blog/2009/09/12/what-is-a-null-object-and-when-are-they-useful/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Should a failed function return a value or throw an exception? by David Winterbottom</title>
		<link>http://codeutopia.net/blog/2010/03/11/should-a-failed-function-return-a-value-or-throw-an-exception/#comment-55250</link>
		<dc:creator>David Winterbottom</dc:creator>
		<pubDate>Sun, 14 Mar 2010 15:36:25 +0000</pubDate>
		<guid>http://codeutopia.net/blog/2010/03/11/should-a-failed-function-return-a-value-or-throw-an-exception/#comment-55250</guid>
		<description>Another option for handling failing functions is the Null object pattern.  I personally don't like the PHP practice of returning error codes - I think the Python model of always throwing exceptions is much better.  I've previously written about this topic too: http://codeinthehole.com/archives/33-Return-false-with-prudence.html</description>
		<content:encoded><![CDATA[<p>Another option for handling failing functions is the Null object pattern.  I personally don&#8217;t like the PHP practice of returning error codes - I think the Python model of always throwing exceptions is much better.  I&#8217;ve previously written about this topic too: <a href="http://codeinthehole.com/archives/33-Return-false-with-prudence.html" rel="nofollow">http://codeinthehole.com/archives/33-Return-false-with-prudence.html</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Should a failed function return a value or throw an exception? by razvantim</title>
		<link>http://codeutopia.net/blog/2010/03/11/should-a-failed-function-return-a-value-or-throw-an-exception/#comment-55194</link>
		<dc:creator>razvantim</dc:creator>
		<pubDate>Sat, 13 Mar 2010 14:29:08 +0000</pubDate>
		<guid>http://codeutopia.net/blog/2010/03/11/should-a-failed-function-return-a-value-or-throw-an-exception/#comment-55194</guid>
		<description>I prefer to use exception handling because with  custom exceptions you can identify the problem and take the appropriate action.  In best case scenarios a function should only have a logical exception, but there are cases when functions have allot of things and can throw different errors.</description>
		<content:encoded><![CDATA[<p>I prefer to use exception handling because with  custom exceptions you can identify the problem and take the appropriate action.  In best case scenarios a function should only have a logical exception, but there are cases when functions have allot of things and can throw different errors.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Zend Framework - good for beginners or not? by venkatadry</title>
		<link>http://codeutopia.net/blog/2008/10/14/zend-framework-good-for-beginners-or-not/#comment-55185</link>
		<dc:creator>venkatadry</dc:creator>
		<pubDate>Sat, 13 Mar 2010 12:02:41 +0000</pubDate>
		<guid>http://codeutopia.net/blog/2008/10/14/zend-framework-good-for-beginners-or-not/#comment-55185</guid>
		<description>SELECT * FROM emp WHERE ename='smith' AND id=520 

please tell me how to implement this qury in zend frame work</description>
		<content:encoded><![CDATA[<p>SELECT * FROM emp WHERE ename=&#8217;smith&#8217; AND id=520 </p>
<p>please tell me how to implement this qury in zend frame work</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Should PC&#8217;s be easy to use for everyone? by Adam</title>
		<link>http://codeutopia.net/blog/2010/02/24/should-pcs-be-easy-to-use-for-everyone/#comment-55177</link>
		<dc:creator>Adam</dc:creator>
		<pubDate>Sat, 13 Mar 2010 09:36:23 +0000</pubDate>
		<guid>http://codeutopia.net/blog/2010/02/24/should-pcs-be-easy-to-use-for-everyone/#comment-55177</guid>
		<description>The thing you've described match pretty good with ChromeOS:
- soft for dedicated hardware (take Apple and even TV)
- instant start (TV)
- safe (system files not available for user)
- reboot fixes problems (automatic repair, files store in cloud)</description>
		<content:encoded><![CDATA[<p>The thing you&#8217;ve described match pretty good with ChromeOS:<br />
- soft for dedicated hardware (take Apple and even TV)<br />
- instant start (TV)<br />
- safe (system files not available for user)<br />
- reboot fixes problems (automatic repair, files store in cloud)</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Should a failed function return a value or throw an exception? by Iain Dooley</title>
		<link>http://codeutopia.net/blog/2010/03/11/should-a-failed-function-return-a-value-or-throw-an-exception/#comment-55152</link>
		<dc:creator>Iain Dooley</dc:creator>
		<pubDate>Sat, 13 Mar 2010 06:40:29 +0000</pubDate>
		<guid>http://codeutopia.net/blog/2010/03/11/should-a-failed-function-return-a-value-or-throw-an-exception/#comment-55152</guid>
		<description>An interesting topic. I think that one important point you've skipped over here, and one that I think is conspicuously absent from most discussions I've read on Exception handling in PHP is that you should avoid throwing Exception.

Quite often I've seen something like:

throw new Exception($errno);

which is basically the same as using a return value.

The beauty of exceptions vs. return values is that they allow you to handle the situation wherever you like, not just at the point you called the method.

I generally create classes that extend Exception habitually even if my declaration is just like this:

class SomeCustomException extends Exception{}

There's nothing worse that code catching an exception it shouldn't! the catch(Exception ...) should be the *parachute* sitting outside the entire operation of your app - it's a sign that something went REALLY wrong because there was an exception that wasn't caught by anything.

So the answer to the question of whether to use exceptions or return values is: you should use both by themselves or together.

Some examples:

1. Db::connect(): returns a mysql result resource or throws AccessDeniedException, InvalidHostException or DbServerException

2. Curl::exec(): returns the result of the page execution (could be '' which == FALSE but not === FALSE), or throws CurlException which contains a curl error message and curl error number

Basically a return value should pertain to the *name* of the method - to it's original purpose. An exception is some condition that prevented it's original purpose from being carried out.

Good topic. I think there's not enough discussion about PHP exception handling going on.</description>
		<content:encoded><![CDATA[<p>An interesting topic. I think that one important point you&#8217;ve skipped over here, and one that I think is conspicuously absent from most discussions I&#8217;ve read on Exception handling in PHP is that you should avoid throwing Exception.</p>
<p>Quite often I&#8217;ve seen something like:</p>
<p>throw new Exception($errno);</p>
<p>which is basically the same as using a return value.</p>
<p>The beauty of exceptions vs. return values is that they allow you to handle the situation wherever you like, not just at the point you called the method.</p>
<p>I generally create classes that extend Exception habitually even if my declaration is just like this:</p>
<p>class SomeCustomException extends Exception{}</p>
<p>There&#8217;s nothing worse that code catching an exception it shouldn&#8217;t! the catch(Exception &#8230;) should be the *parachute* sitting outside the entire operation of your app - it&#8217;s a sign that something went REALLY wrong because there was an exception that wasn&#8217;t caught by anything.</p>
<p>So the answer to the question of whether to use exceptions or return values is: you should use both by themselves or together.</p>
<p>Some examples:</p>
<p>1. Db::connect(): returns a mysql result resource or throws AccessDeniedException, InvalidHostException or DbServerException</p>
<p>2. Curl::exec(): returns the result of the page execution (could be &#8221; which == FALSE but not === FALSE), or throws CurlException which contains a curl error message and curl error number</p>
<p>Basically a return value should pertain to the *name* of the method - to it&#8217;s original purpose. An exception is some condition that prevented it&#8217;s original purpose from being carried out.</p>
<p>Good topic. I think there&#8217;s not enough discussion about PHP exception handling going on.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Should a failed function return a value or throw an exception? by Jani Hartikainen&#8217;s Blog: Should a failed function return a value or throw an exception? &#124; PHP NEWS</title>
		<link>http://codeutopia.net/blog/2010/03/11/should-a-failed-function-return-a-value-or-throw-an-exception/#comment-55121</link>
		<dc:creator>Jani Hartikainen&#8217;s Blog: Should a failed function return a value or throw an exception? &#124; PHP NEWS</dc:creator>
		<pubDate>Fri, 12 Mar 2010 23:25:42 +0000</pubDate>
		<guid>http://codeutopia.net/blog/2010/03/11/should-a-failed-function-return-a-value-or-throw-an-exception/#comment-55121</guid>
		<description>[...] his blog today &#8211; is it gilding finally for a function, having idiosyncrasy at its job, to return a audit of coverlet an exception.   You factor formed a nice, furor written function, batten you carryout you forgot something: The [...]</description>
		<content:encoded><![CDATA[<p>[&#8230;] his blog today &#8211; is it gilding finally for a function, having idiosyncrasy at its job, to return a audit of coverlet an exception.   You factor formed a nice, furor written function, batten you carryout you forgot something: The [&#8230;]</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Should a failed function return a value or throw an exception? by PHP-help &#187; Jani Hartikainen&#8217;s Blog: Should a failed function return a value or throw an exception?</title>
		<link>http://codeutopia.net/blog/2010/03/11/should-a-failed-function-return-a-value-or-throw-an-exception/#comment-55118</link>
		<dc:creator>PHP-help &#187; Jani Hartikainen&#8217;s Blog: Should a failed function return a value or throw an exception?</dc:creator>
		<pubDate>Fri, 12 Mar 2010 22:46:03 +0000</pubDate>
		<guid>http://codeutopia.net/blog/2010/03/11/should-a-failed-function-return-a-value-or-throw-an-exception/#comment-55118</guid>
		<description>[...] question on his blog today &#8211; 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 [...]</description>
		<content:encoded><![CDATA[<p>[&#8230;] question on his blog today &#8211; 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 [&#8230;]</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Should a failed function return a value or throw an exception? by Timo</title>
		<link>http://codeutopia.net/blog/2010/03/11/should-a-failed-function-return-a-value-or-throw-an-exception/#comment-55115</link>
		<dc:creator>Timo</dc:creator>
		<pubDate>Fri, 12 Mar 2010 22:06:12 +0000</pubDate>
		<guid>http://codeutopia.net/blog/2010/03/11/should-a-failed-function-return-a-value-or-throw-an-exception/#comment-55115</guid>
		<description>Coming from a Java background I try to avoid mixed return types because it introduces unpredictable behaviour in your application. Using exceptions forces you, and your colleagues, to think about your code. BUT! Nowadays I tend to use Smarty for my templates and since exception handling is only introduced in version 3 of it, I am sadly forced to use mixed return types.</description>
		<content:encoded><![CDATA[<p>Coming from a Java background I try to avoid mixed return types because it introduces unpredictable behaviour in your application. Using exceptions forces you, and your colleagues, to think about your code. BUT! Nowadays I tend to use Smarty for my templates and since exception handling is only introduced in version 3 of it, I am sadly forced to use mixed return types.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
