<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Exceptions versus Return Values</title>
	<atom:link href="http://www.shaunabram.com/exceptions-vs-return-values-article/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.shaunabram.com</link>
	<description>Java and Technology weblog</description>
	<lastBuildDate>Sun, 05 Feb 2012 22:00:46 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: admin</title>
		<link>http://www.shaunabram.com/exceptions-vs-return-values-article/comment-page-1/#comment-4795</link>
		<dc:creator>admin</dc:creator>
		<pubDate>Wed, 18 Mar 2009 00:43:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.shaunabram.com/?page_id=118#comment-4795</guid>
		<description>Tom,
Thanks for commenting.

I agree that exceptions should only be used for exceptional conditions. The debate lies in what constitutes an exceptional condition. My own definition is a little looser than some other peoples. 

Exceptions definitely shouldn&#039;t be used or normal control flow, but I do think it is OK to use them for dealing with &#039;contingency&#039; situations e.g. to signal a situation that stops a method from completing in its normal way, and that the method itself doesn&#039;t know how to deal with - but that a calling method may know how to deal with and recover from. If that contingency is important enough that it shouldn&#039;t be (accidentally)  ignored, then checked exceptions are a good fit.

I think I did a better job of explaining this in a recent blog posting:

http://www.shaunabram.com/checked-exceptions-article/

Maybe it will change your mind ;-) If not, it would be great to hear your counter views...

Shaun</description>
		<content:encoded><![CDATA[<p>Tom,<br />
Thanks for commenting.</p>
<p>I agree that exceptions should only be used for exceptional conditions. The debate lies in what constitutes an exceptional condition. My own definition is a little looser than some other peoples. </p>
<p>Exceptions definitely shouldn&#8217;t be used or normal control flow, but I do think it is OK to use them for dealing with &#8216;contingency&#8217; situations e.g. to signal a situation that stops a method from completing in its normal way, and that the method itself doesn&#8217;t know how to deal with &#8211; but that a calling method may know how to deal with and recover from. If that contingency is important enough that it shouldn&#8217;t be (accidentally)  ignored, then checked exceptions are a good fit.</p>
<p>I think I did a better job of explaining this in a recent blog posting:</p>
<p><a href="http://www.shaunabram.com/checked-exceptions-article/" rel="nofollow">http://www.shaunabram.com/checked-exceptions-article/</a></p>
<p>Maybe it will change your mind <img src='http://www.shaunabram.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  If not, it would be great to hear your counter views&#8230;</p>
<p>Shaun</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: admin</title>
		<link>http://www.shaunabram.com/exceptions-vs-return-values-article/comment-page-1/#comment-4794</link>
		<dc:creator>admin</dc:creator>
		<pubDate>Wed, 18 Mar 2009 00:29:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.shaunabram.com/?page_id=118#comment-4794</guid>
		<description>Thanks Esteve...

I think I understand what you mean - that when using a return value or Special Result Class, you always get that result back, regardless. But you may well then need do do a series of if blocks for example,

if (result.hasErrors()) {...} 
else {...}

which isn&#039;t really too different from the catch blocks involved with the exceptions approach?

Shaun</description>
		<content:encoded><![CDATA[<p>Thanks Esteve&#8230;</p>
<p>I think I understand what you mean &#8211; that when using a return value or Special Result Class, you always get that result back, regardless. But you may well then need do do a series of if blocks for example,</p>
<p>if (result.hasErrors()) {&#8230;}<br />
else {&#8230;}</p>
<p>which isn&#8217;t really too different from the catch blocks involved with the exceptions approach?</p>
<p>Shaun</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: admin</title>
		<link>http://www.shaunabram.com/exceptions-vs-return-values-article/comment-page-1/#comment-4792</link>
		<dc:creator>admin</dc:creator>
		<pubDate>Tue, 17 Mar 2009 23:58:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.shaunabram.com/?page_id=118#comment-4792</guid>
		<description>Hi Ricky,
Thanks for posting, but I&#039;m not sure I follow it entirely. I think what you are proposing is a new, custom, parameterized type, called &quot;Either&quot; which has a single method called effect(). As well as a new class called Failure? Or am I being slow and it&#039;s actually a standard class/library that I haven&#039;t came across before?

Seems like an interesting idea. If you could point us to any complete code, or posting/docs on it, I&#039;d like to understand it a little better...

And I assume by &#039;a better language&#039; you mean Scala? :-)

Thanks, 

Shaun
</description>
		<content:encoded><![CDATA[<p>Hi Ricky,<br />
Thanks for posting, but I&#8217;m not sure I follow it entirely. I think what you are proposing is a new, custom, parameterized type, called &#8220;Either&#8221; which has a single method called effect(). As well as a new class called Failure? Or am I being slow and it&#8217;s actually a standard class/library that I haven&#8217;t came across before?</p>
<p>Seems like an interesting idea. If you could point us to any complete code, or posting/docs on it, I&#8217;d like to understand it a little better&#8230;</p>
<p>And I assume by &#8216;a better language&#8217; you mean Scala? <img src='http://www.shaunabram.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Thanks, </p>
<p>Shaun</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tom Palmer</title>
		<link>http://www.shaunabram.com/exceptions-vs-return-values-article/comment-page-1/#comment-4786</link>
		<dc:creator>Tom Palmer</dc:creator>
		<pubDate>Tue, 17 Mar 2009 12:35:08 +0000</pubDate>
		<guid isPermaLink="false">http://www.shaunabram.com/?page_id=118#comment-4786</guid>
		<description>I mostly have a simple rule most of the time: Exceptions are for exceptional cases. That is, if you are likely to ignore an error condition and it shouldn&#039;t be ignored, you should make sure to throw an exception rather than use a return value. This covers a great majority of error conditions, I think. Use a special class if you determine that specific identification is valuable, but any exceptions is better than none. Never use checked exceptions.</description>
		<content:encoded><![CDATA[<p>I mostly have a simple rule most of the time: Exceptions are for exceptional cases. That is, if you are likely to ignore an error condition and it shouldn&#8217;t be ignored, you should make sure to throw an exception rather than use a return value. This covers a great majority of error conditions, I think. Use a special class if you determine that specific identification is valuable, but any exceptions is better than none. Never use checked exceptions.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SeanJA</title>
		<link>http://www.shaunabram.com/exceptions-vs-return-values-article/comment-page-1/#comment-4785</link>
		<dc:creator>SeanJA</dc:creator>
		<pubDate>Tue, 17 Mar 2009 12:29:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.shaunabram.com/?page_id=118#comment-4785</guid>
		<description>One thing that frustrates me is when people throw exceptions for error checking and you only get one error back after say... filling out a form, and then you resubmit it to get another error back... and so on...</description>
		<content:encoded><![CDATA[<p>One thing that frustrates me is when people throw exceptions for error checking and you only get one error back after say&#8230; filling out a form, and then you resubmit it to get another error back&#8230; and so on&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Esteve</title>
		<link>http://www.shaunabram.com/exceptions-vs-return-values-article/comment-page-1/#comment-4783</link>
		<dc:creator>Esteve</dc:creator>
		<pubDate>Tue, 17 Mar 2009 11:57:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.shaunabram.com/?page_id=118#comment-4783</guid>
		<description>Good job!
Another problem on using exceptions is that on caller method you don&#039;t know when an exception may be thrown. Using return values/class you know explicitly what may happen. ;)</description>
		<content:encoded><![CDATA[<p>Good job!<br />
Another problem on using exceptions is that on caller method you don&#8217;t know when an exception may be thrown. Using return values/class you know explicitly what may happen. <img src='http://www.shaunabram.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ricky Clarkson</title>
		<link>http://www.shaunabram.com/exceptions-vs-return-values-article/comment-page-1/#comment-4782</link>
		<dc:creator>Ricky Clarkson</dc:creator>
		<pubDate>Tue, 17 Mar 2009 11:43:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.shaunabram.com/?page_id=118#comment-4782</guid>
		<description>Either[Integer, Failure] result = getUserValue();

result.effect(new E[Integer] { public void e(Integer i) { whatever you want if getUserValue succeeded } },
new E[Failure] { public void e(Failure f) { and if it failed } });

I used []s instead of angle brackets to avoid problems with comment formatting.

The above can be prettier if you use a better language.

val result = getUserInput

result match { case Left(i) =&gt; println(&quot;The user specified &quot; + i)
  case Right(f) =&gt; println(&quot;The user is an eejit because &quot; + f)
}</description>
		<content:encoded><![CDATA[<p>Either[Integer, Failure] result = getUserValue();</p>
<p>result.effect(new E[Integer] { public void e(Integer i) { whatever you want if getUserValue succeeded } },<br />
new E[Failure] { public void e(Failure f) { and if it failed } });</p>
<p>I used []s instead of angle brackets to avoid problems with comment formatting.</p>
<p>The above can be prettier if you use a better language.</p>
<p>val result = getUserInput</p>
<p>result match { case Left(i) =&gt; println(&#8220;The user specified &#8221; + i)<br />
  case Right(f) =&gt; println(&#8220;The user is an eejit because &#8221; + f)<br />
}</p>
]]></content:encoded>
	</item>
</channel>
</rss>

