<?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: Try/Catch Blocks Can Hurt Performance Significantly</title>
	<atom:link href="http://www.chinhdo.com/20080226/try-catch-blocks-performance/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.chinhdo.com/20080226/try-catch-blocks-performance/</link>
	<description>Chinh's not quite random thoughts on software development, .NET, gadgets, and other things.</description>
	<lastBuildDate>Tue, 09 Mar 2010 13:15:12 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Chinh Do</title>
		<link>http://www.chinhdo.com/20080226/try-catch-blocks-performance/comment-page-1/#comment-76753</link>
		<dc:creator>Chinh Do</dc:creator>
		<pubDate>Sat, 06 Feb 2010 16:37:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.chinhdo.com/20080226/try-catch-blocks-performance/#comment-76753</guid>
		<description>Hi Derk: Thanks for your comment. I agree with you. My example is an example of bad exception handling, so definitely don&#039;t do it like that. Chinh</description>
		<content:encoded><![CDATA[<p>Hi Derk: Thanks for your comment. I agree with you. My example is an example of bad exception handling, so definitely don&#8217;t do it like that. Chinh</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Derk</title>
		<link>http://www.chinhdo.com/20080226/try-catch-blocks-performance/comment-page-1/#comment-76747</link>
		<dc:creator>Derk</dc:creator>
		<pubDate>Sat, 06 Feb 2010 11:20:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.chinhdo.com/20080226/try-catch-blocks-performance/#comment-76747</guid>
		<description>The thing that I see missing in this discussion is that exceptions should only be used for _exceptional_ behaviour.  In your example, Chinh, you&#039;ve used exceptions for expected behaviour.  In general, exceptions are a great thing, and they don&#039;t affect performance.  Just don&#039;t write code that depends on them being called.</description>
		<content:encoded><![CDATA[<p>The thing that I see missing in this discussion is that exceptions should only be used for _exceptional_ behaviour.  In your example, Chinh, you&#8217;ve used exceptions for expected behaviour.  In general, exceptions are a great thing, and they don&#8217;t affect performance.  Just don&#8217;t write code that depends on them being called.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dmitriy</title>
		<link>http://www.chinhdo.com/20080226/try-catch-blocks-performance/comment-page-1/#comment-69422</link>
		<dc:creator>Dmitriy</dc:creator>
		<pubDate>Tue, 15 Dec 2009 19:00:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.chinhdo.com/20080226/try-catch-blocks-performance/#comment-69422</guid>
		<description>This is would be the best way to do this try catch block
 w.Start();
            int notFound = 0;
            try
            {
                for (int i = 1; i &lt;= 1000000; i++)
                {
                    int value = numbers[i];
                }
            }
            catch
            {
                notFound++;
            }
            this.label1.Text = &quot;Elapsed: &quot; + w.ElapsedMilliseconds + &quot;.&quot;;</description>
		<content:encoded><![CDATA[<p>This is would be the best way to do this try catch block<br />
 w.Start();<br />
            int notFound = 0;<br />
            try<br />
            {<br />
                for (int i = 1; i &lt;= 1000000; i++)<br />
                {<br />
                    int value = numbers[i];<br />
                }<br />
            }<br />
            catch<br />
            {<br />
                notFound++;<br />
            }<br />
            this.label1.Text = &#8220;Elapsed: &#8221; + w.ElapsedMilliseconds + &#8220;.&#8221;;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chinh Do</title>
		<link>http://www.chinhdo.com/20080226/try-catch-blocks-performance/comment-page-1/#comment-53195</link>
		<dc:creator>Chinh Do</dc:creator>
		<pubDate>Wed, 26 Aug 2009 16:47:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.chinhdo.com/20080226/try-catch-blocks-performance/#comment-53195</guid>
		<description>Hi thedudeewr: Thanks for you comment. The point of the ProgrammerHeaven article is absolutely correct... there&#039;s no significant performance issue with one single empty try/catch block.

My main point was only to add &quot;but be careful&quot;... even if the empty try/catch block doesn&#039;t impose any performance issue, we usually have some type of code inside the catch block... and that code may be an issue when it gets triggered, especially in a loop. That&#039;s all.

Anyway, I guess I didn&#039;t say what I wanted to say clearly. I can see how my post could be misunderstood as trying to refute the ProgrammerHeaven&#039;s article.</description>
		<content:encoded><![CDATA[<p>Hi thedudeewr: Thanks for you comment. The point of the ProgrammerHeaven article is absolutely correct&#8230; there&#8217;s no significant performance issue with one single empty try/catch block.</p>
<p>My main point was only to add &#8220;but be careful&#8221;&#8230; even if the empty try/catch block doesn&#8217;t impose any performance issue, we usually have some type of code inside the catch block&#8230; and that code may be an issue when it gets triggered, especially in a loop. That&#8217;s all.</p>
<p>Anyway, I guess I didn&#8217;t say what I wanted to say clearly. I can see how my post could be misunderstood as trying to refute the ProgrammerHeaven&#8217;s article.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: thedudeewr</title>
		<link>http://www.chinhdo.com/20080226/try-catch-blocks-performance/comment-page-1/#comment-53189</link>
		<dc:creator>thedudeewr</dc:creator>
		<pubDate>Wed, 26 Aug 2009 16:08:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.chinhdo.com/20080226/try-catch-blocks-performance/#comment-53189</guid>
		<description>sorry but while you might be true , youre not comparing apples to apples, you should take a class in algorithm analisys. the question is wheter ONE try catch hurts performance (and some memory) , and the article you linked answers this, only adds a litle more to memory and performance, if you insert it in a loop then u multiply this by n so then the algorithm goes to O(n), to prove your point you will have get as result a O(n^2) or higher to make your point.
what you are saying is like comparing creating one integer as opposed to creating integers inside a loop. but anyway good try.</description>
		<content:encoded><![CDATA[<p>sorry but while you might be true , youre not comparing apples to apples, you should take a class in algorithm analisys. the question is wheter ONE try catch hurts performance (and some memory) , and the article you linked answers this, only adds a litle more to memory and performance, if you insert it in a loop then u multiply this by n so then the algorithm goes to O(n), to prove your point you will have get as result a O(n^2) or higher to make your point.<br />
what you are saying is like comparing creating one integer as opposed to creating integers inside a loop. but anyway good try.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chinh Do</title>
		<link>http://www.chinhdo.com/20080226/try-catch-blocks-performance/comment-page-1/#comment-13650</link>
		<dc:creator>Chinh Do</dc:creator>
		<pubDate>Wed, 04 Feb 2009 14:08:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.chinhdo.com/20080226/try-catch-blocks-performance/#comment-13650</guid>
		<description>Andrew:

I do not by any means recommend that try/catch blocks are avoided. I just wanted to stress that there IS a cost when an exception is raised. The programmers heaven article actually stated that as well.

Since you have a loop involved with your exception handling code, I think you are right to re-examine the exception handling code. I would carefully examine any possibility that the exception handling code may get triggered repeatedly. There&#039;s really the only scenario where your performance can be degraded significantly.

Chinh</description>
		<content:encoded><![CDATA[<p>Andrew:</p>
<p>I do not by any means recommend that try/catch blocks are avoided. I just wanted to stress that there IS a cost when an exception is raised. The programmers heaven article actually stated that as well.</p>
<p>Since you have a loop involved with your exception handling code, I think you are right to re-examine the exception handling code. I would carefully examine any possibility that the exception handling code may get triggered repeatedly. There&#8217;s really the only scenario where your performance can be degraded significantly.</p>
<p>Chinh</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andrew Ross</title>
		<link>http://www.chinhdo.com/20080226/try-catch-blocks-performance/comment-page-1/#comment-13532</link>
		<dc:creator>Andrew Ross</dc:creator>
		<pubDate>Wed, 04 Feb 2009 09:30:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.chinhdo.com/20080226/try-catch-blocks-performance/#comment-13532</guid>
		<description>I came to this article after looking at the article from programmers heaven, looking to see if I should bother rewriting the search code for an application I have just inherited.

I was going to leave it as it was after seeing the programmers heaven article.
I didn&#039;t like the try catches everywhere but I thought it wasn&#039;t going to hurt so why bother. After seeing this article I&#039;ll get to removing the try catches and just check to see if the row number exists.

Worst part is the methods that I&#039;m going to rewrite are used in a loop.

Thanks for clearing that up.</description>
		<content:encoded><![CDATA[<p>I came to this article after looking at the article from programmers heaven, looking to see if I should bother rewriting the search code for an application I have just inherited.</p>
<p>I was going to leave it as it was after seeing the programmers heaven article.<br />
I didn&#8217;t like the try catches everywhere but I thought it wasn&#8217;t going to hurt so why bother. After seeing this article I&#8217;ll get to removing the try catches and just check to see if the row number exists.</p>
<p>Worst part is the methods that I&#8217;m going to rewrite are used in a loop.</p>
<p>Thanks for clearing that up.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: chinhdo</title>
		<link>http://www.chinhdo.com/20080226/try-catch-blocks-performance/comment-page-1/#comment-6096</link>
		<dc:creator>chinhdo</dc:creator>
		<pubDate>Wed, 19 Nov 2008 14:09:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.chinhdo.com/20080226/try-catch-blocks-performance/#comment-6096</guid>
		<description>#http://www.chinhdo.com/wp-includes/images/smilies/icon_smile.gif

posted on September 15th, 2008 at 12:21 am
# 14 On September 17th, 2008, Chinh Do said:

    Tommy: Yes you are 100% right. My code example is not a very good one.</description>
		<content:encoded><![CDATA[<p>#http://www.chinhdo.com/wp-includes/images/smilies/icon_smile.gif</p>
<p>posted on September 15th, 2008 at 12:21 am<br />
# 14 On September 17th, 2008, Chinh Do said:</p>
<p>    Tommy: Yes you are 100% right. My code example is not a very good one.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chinh Do</title>
		<link>http://www.chinhdo.com/20080226/try-catch-blocks-performance/comment-page-1/#comment-5057</link>
		<dc:creator>Chinh Do</dc:creator>
		<pubDate>Thu, 18 Sep 2008 00:23:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.chinhdo.com/20080226/try-catch-blocks-performance/#comment-5057</guid>
		<description>Tommy: Yes you are 100% right. My code example is not a very good one.</description>
		<content:encoded><![CDATA[<p>Tommy: Yes you are 100% right. My code example is not a very good one.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: tommy</title>
		<link>http://www.chinhdo.com/20080226/try-catch-blocks-performance/comment-page-1/#comment-5021</link>
		<dc:creator>tommy</dc:creator>
		<pubDate>Mon, 15 Sep 2008 04:21:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.chinhdo.com/20080226/try-catch-blocks-performance/#comment-5021</guid>
		<description>wouldn&#039;t it just be faster to not do any of that code?  Seems like if you skipped it all you could just avoid all the code and exceptions in the first place :)</description>
		<content:encoded><![CDATA[<p>wouldn&#8217;t it just be faster to not do any of that code?  Seems like if you skipped it all you could just avoid all the code and exceptions in the first place <img src='http://www.chinhdo.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
</channel>
</rss>
