<?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 for control flow considered perfectly acceptable, thanks very much</title>
	<atom:link href="http://www.drmaciver.com/2009/03/exceptions-for-control-flow-considered-perfectly-acceptable-thanks-very-much/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.drmaciver.com/2009/03/exceptions-for-control-flow-considered-perfectly-acceptable-thanks-very-much/</link>
	<description></description>
	<lastBuildDate>Sat, 13 Mar 2010 15:45:02 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: masklinn</title>
		<link>http://www.drmaciver.com/2009/03/exceptions-for-control-flow-considered-perfectly-acceptable-thanks-very-much/comment-page-1/#comment-983</link>
		<dc:creator>masklinn</dc:creator>
		<pubDate>Sun, 30 Aug 2009 11:26:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.drmaciver.com/?p=444#comment-983</guid>
		<description>&gt; As far as the exceptional circumstances thing goes: I’d say that it’s meaningless as an argument 

And I&#039;d completely agree with that.</description>
		<content:encoded><![CDATA[<p>&gt; As far as the exceptional circumstances thing goes: I’d say that it’s meaningless as an argument </p>
<p>And I&#8217;d completely agree with that.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: david</title>
		<link>http://www.drmaciver.com/2009/03/exceptions-for-control-flow-considered-perfectly-acceptable-thanks-very-much/comment-page-1/#comment-982</link>
		<dc:creator>david</dc:creator>
		<pubDate>Sat, 29 Aug 2009 16:57:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.drmaciver.com/?p=444#comment-982</guid>
		<description>Hi Masklinn,

You&#039;re quite right: This is hardly a new point (I&#039;m slightly surprised I didn&#039;t mention this). There are a bunch of languages which already do it. OCaml and, to a lesser extent, Haskell also do. 

As far as the exceptional circumstances thing goes: I&#039;d say that it&#039;s meaningless as an argument regardless of whether it&#039;s meaningful as a statement, because as your example shows there&#039;s a lot of wiggle room in what you consider to be exceptional.</description>
		<content:encoded><![CDATA[<p>Hi Masklinn,</p>
<p>You&#8217;re quite right: This is hardly a new point (I&#8217;m slightly surprised I didn&#8217;t mention this). There are a bunch of languages which already do it. OCaml and, to a lesser extent, Haskell also do. </p>
<p>As far as the exceptional circumstances thing goes: I&#8217;d say that it&#8217;s meaningless as an argument regardless of whether it&#8217;s meaningful as a statement, because as your example shows there&#8217;s a lot of wiggle room in what you consider to be exceptional.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: masklinn</title>
		<link>http://www.drmaciver.com/2009/03/exceptions-for-control-flow-considered-perfectly-acceptable-thanks-very-much/comment-page-1/#comment-981</link>
		<dc:creator>masklinn</dc:creator>
		<pubDate>Sat, 29 Aug 2009 15:34:08 +0000</pubDate>
		<guid isPermaLink="false">http://www.drmaciver.com/?p=444#comment-981</guid>
		<description>David, I just found/read this article (and the previous one) and wanted to point out that there are existing languages which very successfully use exceptions for control flow.

One of these is Python, which mainly does it at two levels:

* Python&#039;s Iterator protocol is made of two methods __iter__ and next(), __iter__ returns the iterator and next() returns the next item in the iterator. You&#039;ll notice there is no has_next() method, and that&#039;s because when calling next() on an expanded iterator, the iterator simply throws StopIteration.

* Error handling/condition checking (or the lack thereof). The Python community broadly subscribes to the EAFP principle: it&#039;s easier to ask for forgiveness than permission, so if you want something just do it and if things break clean up.

One of the classic example of this is fetching a value (which may or may not be there) from a map. Java code will pretty much always take the form

    if(map.containsKey(someKey)) {
        T value = map.get(someKey);
    } else {
        // stuff to do if someKey wasn&#039;t in the map
    }

while Python code, though it will be found in this form as well (tends to vary based on the number of misses expected, mostly) will very often read:

    try:
        value = my_dict[some_key]
    except KeyError:
        # stuff to do if some_key isn&#039;t in my_dict

And as an aside, that doesn&#039;t mean &quot;Exceptions are for exceptional situations&quot; is meaningless, the issue here is what people consider &quot;exceptional circumstances&quot;. I tend to like Python&#039;s approach of &quot;yeah when you&#039;re iterating having a next item is normal. Not having one is exceptional&quot;.</description>
		<content:encoded><![CDATA[<p>David, I just found/read this article (and the previous one) and wanted to point out that there are existing languages which very successfully use exceptions for control flow.</p>
<p>One of these is Python, which mainly does it at two levels:</p>
<p>* Python&#8217;s Iterator protocol is made of two methods __iter__ and next(), __iter__ returns the iterator and next() returns the next item in the iterator. You&#8217;ll notice there is no has_next() method, and that&#8217;s because when calling next() on an expanded iterator, the iterator simply throws StopIteration.</p>
<p>* Error handling/condition checking (or the lack thereof). The Python community broadly subscribes to the EAFP principle: it&#8217;s easier to ask for forgiveness than permission, so if you want something just do it and if things break clean up.</p>
<p>One of the classic example of this is fetching a value (which may or may not be there) from a map. Java code will pretty much always take the form</p>
<p>    if(map.containsKey(someKey)) {<br />
        T value = map.get(someKey);<br />
    } else {<br />
        // stuff to do if someKey wasn&#8217;t in the map<br />
    }</p>
<p>while Python code, though it will be found in this form as well (tends to vary based on the number of misses expected, mostly) will very often read:</p>
<p>    try:<br />
        value = my_dict[some_key]<br />
    except KeyError:<br />
        # stuff to do if some_key isn&#8217;t in my_dict</p>
<p>And as an aside, that doesn&#8217;t mean &#8220;Exceptions are for exceptional situations&#8221; is meaningless, the issue here is what people consider &#8220;exceptional circumstances&#8221;. I tend to like Python&#8217;s approach of &#8220;yeah when you&#8217;re iterating having a next item is normal. Not having one is exceptional&#8221;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: david</title>
		<link>http://www.drmaciver.com/2009/03/exceptions-for-control-flow-considered-perfectly-acceptable-thanks-very-much/comment-page-1/#comment-976</link>
		<dc:creator>david</dc:creator>
		<pubDate>Thu, 20 Aug 2009 07:56:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.drmaciver.com/?p=444#comment-976</guid>
		<description>Yes, I agree with your addendum about custom exceptions: Most exceptions whose intended use case is actual error reporting should not be used for control flow. I was sortof implicitly assuming that, but I should have stated it outright. Even if one ignores the performance issues (which are still *relatively* mild), treating errors as control flow conditions which you don&#039;t feel the need to report on is a very dubious practice which can mask some genuine errors (and I&#039;ve seen this happen in real life. Sigh)</description>
		<content:encoded><![CDATA[<p>Yes, I agree with your addendum about custom exceptions: Most exceptions whose intended use case is actual error reporting should not be used for control flow. I was sortof implicitly assuming that, but I should have stated it outright. Even if one ignores the performance issues (which are still *relatively* mild), treating errors as control flow conditions which you don&#8217;t feel the need to report on is a very dubious practice which can mask some genuine errors (and I&#8217;ve seen this happen in real life. Sigh)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Richard Ver Steeg</title>
		<link>http://www.drmaciver.com/2009/03/exceptions-for-control-flow-considered-perfectly-acceptable-thanks-very-much/comment-page-1/#comment-974</link>
		<dc:creator>Richard Ver Steeg</dc:creator>
		<pubDate>Wed, 19 Aug 2009 19:16:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.drmaciver.com/?p=444#comment-974</guid>
		<description>First off, not  arguing against your main thesis -  that implementing exceptions for control flow is a viable option. I&#039;m not prepared to argue fervently for it either. My concern is that you&#039;ve buried a critical caveat in a linked article. The key points of the article should be featured prominently in the main body of your post.

Under the &quot;Exceptions are Slow&quot; heading you say 

  The JVM too (with some mild tricks) has very fast exceptions.

The parenthetical comment, &quot;with some mild tricks&quot;, links to a very critical caveat - Java exceptions are much faster: 

IF you write  custom exception classes
IF you explicitly disable stack trace generation in your custom classes
IF you exclusively use custom exception classes for control flow

In contrast, Exceptions that were designed for error handling do generate stack traces. I have found more then a few examples of code implementing control flow using exceptions designed for error handling.

A better title for your post would be:

  &quot;Custom exceptions for control flow considered perfectly acceptable, thanks very much&quot;

The new initial word is key.

A final observation - you argue that the phrase &quot;Exceptions are for exceptional situations&quot; is meaningless. The phrase may sacrifice strict accuracy for catchiness, and there are certainly ambiguous cases. But in day-to-day programming, I don&#039;t spend time anguishing over whether a condition is an exception condition or a control flow condition. The distinction between the two  is clear; I handle control flow the old-fashioned way and throw exceptions for errors.</description>
		<content:encoded><![CDATA[<p>First off, not  arguing against your main thesis &#8211;  that implementing exceptions for control flow is a viable option. I&#8217;m not prepared to argue fervently for it either. My concern is that you&#8217;ve buried a critical caveat in a linked article. The key points of the article should be featured prominently in the main body of your post.</p>
<p>Under the &#8220;Exceptions are Slow&#8221; heading you say </p>
<p>  The JVM too (with some mild tricks) has very fast exceptions.</p>
<p>The parenthetical comment, &#8220;with some mild tricks&#8221;, links to a very critical caveat &#8211; Java exceptions are much faster: </p>
<p>IF you write  custom exception classes<br />
IF you explicitly disable stack trace generation in your custom classes<br />
IF you exclusively use custom exception classes for control flow</p>
<p>In contrast, Exceptions that were designed for error handling do generate stack traces. I have found more then a few examples of code implementing control flow using exceptions designed for error handling.</p>
<p>A better title for your post would be:</p>
<p>  &#8220;Custom exceptions for control flow considered perfectly acceptable, thanks very much&#8221;</p>
<p>The new initial word is key.</p>
<p>A final observation &#8211; you argue that the phrase &#8220;Exceptions are for exceptional situations&#8221; is meaningless. The phrase may sacrifice strict accuracy for catchiness, and there are certainly ambiguous cases. But in day-to-day programming, I don&#8217;t spend time anguishing over whether a condition is an exception condition or a control flow condition. The distinction between the two  is clear; I handle control flow the old-fashioned way and throw exceptions for errors.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
