<?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: In Praise of Draconian Error Handling, Part 1</title>
	<atom:link href="http://cafe.elharo.com/programming/in-praise-of-draconian-error-handling-part-1/feed/" rel="self" type="application/rss+xml" />
	<link>http://cafe.elharo.com/programming/in-praise-of-draconian-error-handling-part-1/</link>
	<description>Longer than a blog; shorter than a book</description>
	<lastBuildDate>Tue, 09 Mar 2010 18:31:23 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Oleg</title>
		<link>http://cafe.elharo.com/programming/in-praise-of-draconian-error-handling-part-1/comment-page-1/#comment-344112</link>
		<dc:creator>Oleg</dc:creator>
		<pubDate>Wed, 28 Jan 2009 14:26:00 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/?p=376#comment-344112</guid>
		<description>If you think that something will not happen than throw AssertionError instead of RuntimeException.

The probability that you will accidentally mask AssertionError somewehre else in your code is much lower than the probability to accidentally mask RuntimeException.</description>
		<content:encoded><![CDATA[<p>If you think that something will not happen than throw AssertionError instead of RuntimeException.</p>
<p>The probability that you will accidentally mask AssertionError somewehre else in your code is much lower than the probability to accidentally mask RuntimeException.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gareth Rees</title>
		<link>http://cafe.elharo.com/programming/in-praise-of-draconian-error-handling-part-1/comment-page-1/#comment-336680</link>
		<dc:creator>Gareth Rees</dc:creator>
		<pubDate>Tue, 13 Jan 2009 14:01:30 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/?p=376#comment-336680</guid>
		<description>&lt;i&gt;they need to fail fast in the face of internal bugs&lt;/i&gt;

I disagree with this claim. It depends on the environment, on the expertise of the users, and on the consequences of the various kinds of failure.

Video games is an application area I know fairly well. Here it&#039;s vital to &quot;fail fast&quot; &lt;i&gt;in development&lt;/i&gt;, when you have a chance to analyze and fix the problem. But &lt;i&gt;on a console&lt;/i&gt;, failing fast is almost always wrong. There&#039;s nothing the player can do about it, and nothing much you could do about it even if the player could report the bug to you; the game completed its manufacturing run long ago and you have no way of issuing a patch.

There&#039;s almost always some way to handle an error that allows the game to continue running, or which minimizes the consequence of the error for the player. Even when there&#039;s nothing you can do, often the game will be able to limp along despite the error. For example, in development we perform &lt;a href=&quot;http://www.memorymanagement.org/glossary/f.html#fencepost&quot; rel=&quot;nofollow&quot;&gt;fencepost checking&lt;/a&gt; on all allocated memory blocks to detect buffer overruns and other memory corruption errors. But in release we don&#039;t bother: there&#039;s a chance that the undetected memory corruption is harmless, or merely overwrites part of a texture, resulting in graphic corruption but leaving the game still playable. And the worst that can happen is that the game crashes, which from the player&#039;s point of view is no worse than the game throwing an exception.

The decision might be different for PC games because there you do have the possibility of issuing a patch. But that&#039;s exactly my point: the environment matters.</description>
		<content:encoded><![CDATA[<p><i>they need to fail fast in the face of internal bugs</i></p>
<p>I disagree with this claim. It depends on the environment, on the expertise of the users, and on the consequences of the various kinds of failure.</p>
<p>Video games is an application area I know fairly well. Here it&#8217;s vital to &#8220;fail fast&#8221; <i>in development</i>, when you have a chance to analyze and fix the problem. But <i>on a console</i>, failing fast is almost always wrong. There&#8217;s nothing the player can do about it, and nothing much you could do about it even if the player could report the bug to you; the game completed its manufacturing run long ago and you have no way of issuing a patch.</p>
<p>There&#8217;s almost always some way to handle an error that allows the game to continue running, or which minimizes the consequence of the error for the player. Even when there&#8217;s nothing you can do, often the game will be able to limp along despite the error. For example, in development we perform <a href="http://www.memorymanagement.org/glossary/f.html#fencepost" rel="nofollow">fencepost checking</a> on all allocated memory blocks to detect buffer overruns and other memory corruption errors. But in release we don&#8217;t bother: there&#8217;s a chance that the undetected memory corruption is harmless, or merely overwrites part of a texture, resulting in graphic corruption but leaving the game still playable. And the worst that can happen is that the game crashes, which from the player&#8217;s point of view is no worse than the game throwing an exception.</p>
<p>The decision might be different for PC games because there you do have the possibility of issuing a patch. But that&#8217;s exactly my point: the environment matters.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Elliotte Rusty Harold</title>
		<link>http://cafe.elharo.com/programming/in-praise-of-draconian-error-handling-part-1/comment-page-1/#comment-336399</link>
		<dc:creator>Elliotte Rusty Harold</dc:creator>
		<pubDate>Tue, 13 Jan 2009 01:43:01 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/?p=376#comment-336399</guid>
		<description>Gareth, there&#039;s an important distinction between problems caused by external conditions and problems caused by internal bugs. Programs need to be robust in the face of all possible external conditions. However they need to fail fast in the face of internal bugs. In Java this is the difference between checked and runtime exceptions. 

I may eventually move to a map structure if it seems necessary. The problem is the map is too large to embed in source code, close to 100,000 entries. Perhaps some other data structure may prove useful. If this isn&#039;t fast enough, I&#039;ll investigate. However the biggest concern right now is not code speed but code size. the current method skirts close to the boundaries of the maximum method size in Java, and not all tools can handle. This revision should reduce the method down to maybe a fifth of its current size and probaboly be faster to boot.</description>
		<content:encoded><![CDATA[<p>Gareth, there&#8217;s an important distinction between problems caused by external conditions and problems caused by internal bugs. Programs need to be robust in the face of all possible external conditions. However they need to fail fast in the face of internal bugs. In Java this is the difference between checked and runtime exceptions. </p>
<p>I may eventually move to a map structure if it seems necessary. The problem is the map is too large to embed in source code, close to 100,000 entries. Perhaps some other data structure may prove useful. If this isn&#8217;t fast enough, I&#8217;ll investigate. However the biggest concern right now is not code speed but code size. the current method skirts close to the boundaries of the maximum method size in Java, and not all tools can handle. This revision should reduce the method down to maybe a fifth of its current size and probaboly be faster to boot.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: AndyT (lordpixel)</title>
		<link>http://cafe.elharo.com/programming/in-praise-of-draconian-error-handling-part-1/comment-page-1/#comment-336352</link>
		<dc:creator>AndyT (lordpixel)</dc:creator>
		<pubDate>Mon, 12 Jan 2009 22:51:30 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/?p=376#comment-336352</guid>
		<description>Gareth, I believe ERH&#039;s overriding concern is parsing performance, and the switch wins.

There are lots of alternatives in Java, but they all run more slowly.</description>
		<content:encoded><![CDATA[<p>Gareth, I believe ERH&#8217;s overriding concern is parsing performance, and the switch wins.</p>
<p>There are lots of alternatives in Java, but they all run more slowly.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Cowan</title>
		<link>http://cafe.elharo.com/programming/in-praise-of-draconian-error-handling-part-1/comment-page-1/#comment-336295</link>
		<dc:creator>John Cowan</dc:creator>
		<pubDate>Mon, 12 Jan 2009 20:53:49 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/?p=376#comment-336295</guid>
		<description>Nothing in the Unicode data files is hexadecimal except the codepoint itself.  In particular, the values of Canonical Combining Codes are definitely decimal.</description>
		<content:encoded><![CDATA[<p>Nothing in the Unicode data files is hexadecimal except the codepoint itself.  In particular, the values of Canonical Combining Codes are definitely decimal.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gareth Rees</title>
		<link>http://cafe.elharo.com/programming/in-praise-of-draconian-error-handling-part-1/comment-page-1/#comment-336284</link>
		<dc:creator>Gareth Rees</dc:creator>
		<pubDate>Mon, 12 Jan 2009 20:34:10 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/?p=376#comment-336284</guid>
		<description>It would be nice if &lt;pre&gt; worked in comments. Also, it would be nice to have comment preview.</description>
		<content:encoded><![CDATA[<p>It would be nice if &lt;pre&gt; worked in comments. Also, it would be nice to have comment preview.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gareth Rees</title>
		<link>http://cafe.elharo.com/programming/in-praise-of-draconian-error-handling-part-1/comment-page-1/#comment-336279</link>
		<dc:creator>Gareth Rees</dc:creator>
		<pubDate>Mon, 12 Jan 2009 20:14:23 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/?p=376#comment-336279</guid>
		<description>On the general question of what to do in the event of a unanticipated error, surely the right approach depends on the application environment and intended group of users? In a development or testing environment, or when the users are sophisticated (e.g. your own test department, or programmers using your product), it&#039;s absolutely the right thing to raise an exception in response to any unanticipated event. But in a production environment with ordinary users it&#039;s essential that programs cope with unanticipated events. The archetypal case is that of embedded systems: when your car&#039;s engine management system gets a bogus value from the fuel injection subsystem, it would be a bad idea to throw an exception and abort.

I work in video games, where there are similar issues. If you get a bad result from a subsystem, you have to do something: it&#039;s not acceptable just to crash or report a fatal error. Maybe the networking subsystem has gone wrong, but if the game continues to run then at least the player may be able to save their game.

During testing, of course, it&#039;s vital to be informed about unanticipated events, so the general technique we use looks like this:


    if (unanticipated_event) {
        if (testing) {
            assert(false, &quot;Unexpected result: ... details here ...&quot;);
        }
        // Do something sensible,
        // e.g. drop into the handling code for a different error,
        // or as a last resort just carry on as if nothing happened.
    }


In the specific case of your XOM Unicode program, the highly repetitive structure looks really unfortunate. Is there nothing in Java to help you with this? In a language like Python or JavaScript with built-in hash tables you&#039;d write something like:


   data = {
        0x0: &quot;NOT_REORDERED&quot;,
        0x1: &quot;OVERLAY&quot;,
        0x7: &quot;NUKTA&quot;,
        0x8: &quot;KANA_VOICING&quot;,
        0x9: &quot;VIRAMA&quot;,
        # etc ...
    }
    try:
        return result + data[i]
    except KeyError:
        # Handle the unexpected key here.


And in C or C++ you could use the &lt;a href=&quot;http://garethrees.org/2007/04/24/relational-macros/&quot; rel=&quot;nofollow&quot;&gt;relational macros&lt;/a&gt; technique.</description>
		<content:encoded><![CDATA[<p>On the general question of what to do in the event of a unanticipated error, surely the right approach depends on the application environment and intended group of users? In a development or testing environment, or when the users are sophisticated (e.g. your own test department, or programmers using your product), it&#8217;s absolutely the right thing to raise an exception in response to any unanticipated event. But in a production environment with ordinary users it&#8217;s essential that programs cope with unanticipated events. The archetypal case is that of embedded systems: when your car&#8217;s engine management system gets a bogus value from the fuel injection subsystem, it would be a bad idea to throw an exception and abort.</p>
<p>I work in video games, where there are similar issues. If you get a bad result from a subsystem, you have to do something: it&#8217;s not acceptable just to crash or report a fatal error. Maybe the networking subsystem has gone wrong, but if the game continues to run then at least the player may be able to save their game.</p>
<p>During testing, of course, it&#8217;s vital to be informed about unanticipated events, so the general technique we use looks like this:</p>
<p>    if (unanticipated_event) {<br />
        if (testing) {<br />
            assert(false, &#8220;Unexpected result: &#8230; details here &#8230;&#8221;);<br />
        }<br />
        // Do something sensible,<br />
        // e.g. drop into the handling code for a different error,<br />
        // or as a last resort just carry on as if nothing happened.<br />
    }</p>
<p>In the specific case of your XOM Unicode program, the highly repetitive structure looks really unfortunate. Is there nothing in Java to help you with this? In a language like Python or JavaScript with built-in hash tables you&#8217;d write something like:</p>
<p>   data = {<br />
        0&#215;0: &#8220;NOT_REORDERED&#8221;,<br />
        0&#215;1: &#8220;OVERLAY&#8221;,<br />
        0&#215;7: &#8220;NUKTA&#8221;,<br />
        0&#215;8: &#8220;KANA_VOICING&#8221;,<br />
        0&#215;9: &#8220;VIRAMA&#8221;,<br />
        # etc &#8230;<br />
    }<br />
    try:<br />
        return result + data[i]<br />
    except KeyError:<br />
        # Handle the unexpected key here.</p>
<p>And in C or C++ you could use the <a href="http://garethrees.org/2007/04/24/relational-macros/" rel="nofollow">relational macros</a> technique.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ed</title>
		<link>http://cafe.elharo.com/programming/in-praise-of-draconian-error-handling-part-1/comment-page-1/#comment-336260</link>
		<dc:creator>ed</dc:creator>
		<pubDate>Mon, 12 Jan 2009 18:51:02 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/?p=376#comment-336260</guid>
		<description>For the record, I think it&#039;s better to throw an Error in these situations, rather than a RuntimeException.  YMMV.

Sometimes users will have code with a &#039;catch (Exception e)&#039; and an empty block, effectively ignoring all Exceptions, of which RuntimeException is a subclass.  Throwing Error avoids this, although it can still get caught with &#039;catch (Throwable t)&#039;, so no amount of fool-proofing can avoid a truly dedicated fool.

And I also suggest prefixing the toHexString() value with &quot;0x&quot;, to avoid propagating the ambiguity you fell prey to.</description>
		<content:encoded><![CDATA[<p>For the record, I think it&#8217;s better to throw an Error in these situations, rather than a RuntimeException.  YMMV.</p>
<p>Sometimes users will have code with a &#8216;catch (Exception e)&#8217; and an empty block, effectively ignoring all Exceptions, of which RuntimeException is a subclass.  Throwing Error avoids this, although it can still get caught with &#8216;catch (Throwable t)&#8217;, so no amount of fool-proofing can avoid a truly dedicated fool.</p>
<p>And I also suggest prefixing the toHexString() value with &#8220;0x&#8221;, to avoid propagating the ambiguity you fell prey to.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
