<?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: The best way to handle exceptions</title>
	<atom:link href="http://www.drmaciver.com/2010/04/the-best-way-to-handle-exceptions/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.drmaciver.com/2010/04/the-best-way-to-handle-exceptions/</link>
	<description></description>
	<lastBuildDate>Mon, 06 Feb 2012 22:56:11 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: @ndy</title>
		<link>http://www.drmaciver.com/2010/04/the-best-way-to-handle-exceptions/#comment-1975</link>
		<dc:creator>@ndy</dc:creator>
		<pubDate>Tue, 21 Jun 2011 10:20:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.drmaciver.com/?p=3860#comment-1975</guid>
		<description>I think that this feeds into higher level design issues. Often you don&#039;t want the program to crash. Perhaps because you&#039;ve built it as a big monolith and have lots of state that you need to save; or whatever. If you&#039;re using a multiprogramming approach with lots of tools that do one thing well then it matters less if that one program crashes as opposed to the entire stack.</description>
		<content:encoded><![CDATA[<p>I think that this feeds into higher level design issues. Often you don&#8217;t want the program to crash. Perhaps because you&#8217;ve built it as a big monolith and have lots of state that you need to save; or whatever. If you&#8217;re using a multiprogramming approach with lots of tools that do one thing well then it matters less if that one program crashes as opposed to the entire stack.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dave Hall</title>
		<link>http://www.drmaciver.com/2010/04/the-best-way-to-handle-exceptions/#comment-1933</link>
		<dc:creator>Dave Hall</dc:creator>
		<pubDate>Wed, 15 Jun 2011 17:27:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.drmaciver.com/?p=3860#comment-1933</guid>
		<description>Something worth pointing out here is the new error handling mechanisms that were introduced in Python 3.1. This new feature made the Java-style exception wrapping / chaining built-in to the language.

Thus, in Python 3, it&#039;s now okay to write:

try:
    connect_to_server()
except IOError as ex:
    raise CouldNotConnectToServerError(&quot;Could not connect to the server&quot;)

This code snippet, rather than hiding the original error, actually adds a nicer user-friendly message to the stack trace. The resultant output, if allowed to propagate and crash the program, looks something like this:

CouldNotConnectToServerError &quot;Could not connect to the server&quot;
Line 4 in server.py

This exception was caused by IOError &quot;DNS did not resolve&quot;
Line 354 in dns.py
Line 200 in net.py
Line 456 in foo.py

And so on. Yes, it&#039;s basically the same as the Java wrapping method, but it encourages a workflow whereby you don&#039;t have to worry about hiding debugging information by raising your own, more helpful exceptions. Rather than one giant stack trace, you have several bitesize ones. Obviously, you can still just print to stderr and exit, but at least now you have to try a bit harder to hide valuable information.</description>
		<content:encoded><![CDATA[<p>Something worth pointing out here is the new error handling mechanisms that were introduced in Python 3.1. This new feature made the Java-style exception wrapping / chaining built-in to the language.</p>
<p>Thus, in Python 3, it&#8217;s now okay to write:</p>
<p>try:<br />
    connect_to_server()<br />
except IOError as ex:<br />
    raise CouldNotConnectToServerError(&#8220;Could not connect to the server&#8221;)</p>
<p>This code snippet, rather than hiding the original error, actually adds a nicer user-friendly message to the stack trace. The resultant output, if allowed to propagate and crash the program, looks something like this:</p>
<p>CouldNotConnectToServerError &#8220;Could not connect to the server&#8221;<br />
Line 4 in server.py</p>
<p>This exception was caused by IOError &#8220;DNS did not resolve&#8221;<br />
Line 354 in dns.py<br />
Line 200 in net.py<br />
Line 456 in foo.py</p>
<p>And so on. Yes, it&#8217;s basically the same as the Java wrapping method, but it encourages a workflow whereby you don&#8217;t have to worry about hiding debugging information by raising your own, more helpful exceptions. Rather than one giant stack trace, you have several bitesize ones. Obviously, you can still just print to stderr and exit, but at least now you have to try a bit harder to hide valuable information.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: david</title>
		<link>http://www.drmaciver.com/2010/04/the-best-way-to-handle-exceptions/#comment-1149</link>
		<dc:creator>david</dc:creator>
		<pubDate>Tue, 27 Apr 2010 20:10:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.drmaciver.com/?p=3860#comment-1149</guid>
		<description>Please read the article before commenting. That is not what people are doing that I am objecting to.</description>
		<content:encoded><![CDATA[<p>Please read the article before commenting. That is not what people are doing that I am objecting to.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt</title>
		<link>http://www.drmaciver.com/2010/04/the-best-way-to-handle-exceptions/#comment-1148</link>
		<dc:creator>Matt</dc:creator>
		<pubDate>Tue, 27 Apr 2010 19:52:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.drmaciver.com/?p=3860#comment-1148</guid>
		<description>&quot;So by including this rescue, we have lost information.&quot;

In Java you can specify a cause in .Net an InnerException, so you don&#039;t lose any information but add to it. I&#039;m sure other platforms have similar facilities.</description>
		<content:encoded><![CDATA[<p>&#8220;So by including this rescue, we have lost information.&#8221;</p>
<p>In Java you can specify a cause in .Net an InnerException, so you don&#8217;t lose any information but add to it. I&#8217;m sure other platforms have similar facilities.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: david</title>
		<link>http://www.drmaciver.com/2010/04/the-best-way-to-handle-exceptions/#comment-1147</link>
		<dc:creator>david</dc:creator>
		<pubDate>Tue, 27 Apr 2010 14:15:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.drmaciver.com/?p=3860#comment-1147</guid>
		<description>Note that I specifically listed that as a case where actually a friendly error message is more appropriate. Also note that you are the only person who has made &quot;new&quot; an issue. I don&#039;t care about new, I care about correct.

However a much larger category of error messages, particularly in server side programming, which you were claiming as &quot;user generated&quot; are in fact entirely the fault of the programmer and are better left untouched without obfuscation (and even in the case where they are caused by the user you damn well better be logging the actual reason for when you screw up)</description>
		<content:encoded><![CDATA[<p>Note that I specifically listed that as a case where actually a friendly error message is more appropriate. Also note that you are the only person who has made &#8220;new&#8221; an issue. I don&#8217;t care about new, I care about correct.</p>
<p>However a much larger category of error messages, particularly in server side programming, which you were claiming as &#8220;user generated&#8221; are in fact entirely the fault of the programmer and are better left untouched without obfuscation (and even in the case where they are caused by the user you damn well better be logging the actual reason for when you screw up)</p>
]]></content:encoded>
	</item>
</channel>
</rss>

