<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.3" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>
<channel>
	<title>Comments on: Try/Catch Blocks Can Hurt Performance Significantly</title>
	<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>
	<pubDate>Sat, 11 Oct 2008 02:17:04 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3</generator>
		<item>
		<title>By: Chinh Do</title>
		<link>http://www.chinhdo.com/20080226/try-catch-blocks-performance/#comment-5057</link>
		<dc:creator>Chinh Do</dc:creator>
		<pubDate>Thu, 18 Sep 2008 00:23:24 +0000</pubDate>
		<guid>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-5021</link>
		<dc:creator>tommy</dc:creator>
		<pubDate>Mon, 15 Sep 2008 04:21:34 +0000</pubDate>
		<guid>http://www.chinhdo.com/20080226/try-catch-blocks-performance/#comment-5021</guid>
		<description>wouldn'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>
	<item>
		<title>By: Luís Soares</title>
		<link>http://www.chinhdo.com/20080226/try-catch-blocks-performance/#comment-3789</link>
		<dc:creator>Luís Soares</dc:creator>
		<pubDate>Fri, 20 Jun 2008 12:55:40 +0000</pubDate>
		<guid>http://www.chinhdo.com/20080226/try-catch-blocks-performance/#comment-3789</guid>
		<description>Wouldn't be faster to get the list of keys and only iterate on them?</description>
		<content:encoded><![CDATA[<p>Wouldn&#8217;t be faster to get the list of keys and only iterate on them?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Milivoj Savin</title>
		<link>http://www.chinhdo.com/20080226/try-catch-blocks-performance/#comment-3398</link>
		<dc:creator>Milivoj Savin</dc:creator>
		<pubDate>Wed, 16 Apr 2008 09:33:00 +0000</pubDate>
		<guid>http://www.chinhdo.com/20080226/try-catch-blocks-performance/#comment-3398</guid>
		<description>James,

Your answer only works if you know that all your keys are all in the range 1 to 1000000. What if the container has a key of 1000001 in it? Can't Count that.</description>
		<content:encoded><![CDATA[<p>James,</p>
<p>Your answer only works if you know that all your keys are all in the range 1 to 1000000. What if the container has a key of 1000001 in it? Can&#8217;t Count that.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ovation</title>
		<link>http://www.chinhdo.com/20080226/try-catch-blocks-performance/#comment-3174</link>
		<dc:creator>ovation</dc:creator>
		<pubDate>Fri, 14 Mar 2008 12:02:35 +0000</pubDate>
		<guid>http://www.chinhdo.com/20080226/try-catch-blocks-performance/#comment-3174</guid>
		<description>Chinh,

This is a great example, bah on the nay-sayers. We are smart enough to know what you mean. Thanks for showing how some simple design decisions and checking can enhance performance!

Keep up the good work, love the blog!

-brian</description>
		<content:encoded><![CDATA[<p>Chinh,</p>
<p>This is a great example, bah on the nay-sayers. We are smart enough to know what you mean. Thanks for showing how some simple design decisions and checking can enhance performance!</p>
<p>Keep up the good work, love the blog!</p>
<p>-brian</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chinh Do</title>
		<link>http://www.chinhdo.com/20080226/try-catch-blocks-performance/#comment-2988</link>
		<dc:creator>Chinh Do</dc:creator>
		<pubDate>Wed, 27 Feb 2008 21:18:31 +0000</pubDate>
		<guid>http://www.chinhdo.com/20080226/try-catch-blocks-performance/#comment-2988</guid>
		<description>James:

I guess I could have done a better job explaining the code example. Perhaps a comment here and there would have helped.

My point was not to demonstrate good/realistic algorithm, but to highlight the fact that bad exception handling practice can potentially be harmful to your performance. If it helped, please pretend that the Dictionary is passed to you from somewhere else. I don't think anybody would write real code like that.

Nice alternate algorithm though.</description>
		<content:encoded><![CDATA[<p>James:</p>
<p>I guess I could have done a better job explaining the code example. Perhaps a comment here and there would have helped.</p>
<p>My point was not to demonstrate good/realistic algorithm, but to highlight the fact that bad exception handling practice can potentially be harmful to your performance. If it helped, please pretend that the Dictionary is passed to you from somewhere else. I don&#8217;t think anybody would write real code like that.</p>
<p>Nice alternate algorithm though.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James Curran</title>
		<link>http://www.chinhdo.com/20080226/try-catch-blocks-performance/#comment-2982</link>
		<dc:creator>James Curran</dc:creator>
		<pubDate>Wed, 27 Feb 2008 17:26:28 +0000</pubDate>
		<guid>http://www.chinhdo.com/20080226/try-catch-blocks-performance/#comment-2982</guid>
		<description>Ok, I'm ignoring the entire point of the article, but ....isn't the actual "correct" method:

int notused = 1000000 - numbers.Count;

Yes, using exceptions for non-exception occurences is bad.  Dumb algorithms are just as bad.</description>
		<content:encoded><![CDATA[<p>Ok, I&#8217;m ignoring the entire point of the article, but &#8230;.isn&#8217;t the actual &#8220;correct&#8221; method:</p>
<p>int notused = 1000000 - numbers.Count;</p>
<p>Yes, using exceptions for non-exception occurences is bad.  Dumb algorithms are just as bad.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Reflective Perspective - Chris Alcock &#187; The Morning Brew #41</title>
		<link>http://www.chinhdo.com/20080226/try-catch-blocks-performance/#comment-2981</link>
		<dc:creator>Reflective Perspective - Chris Alcock &#187; The Morning Brew #41</dc:creator>
		<pubDate>Wed, 27 Feb 2008 08:21:55 +0000</pubDate>
		<guid>http://www.chinhdo.com/20080226/try-catch-blocks-performance/#comment-2981</guid>
		<description>[...] Try/Catch Blocks Can Hurt Performance Significantly - The Try/Catch performance debate continues&#8230; [...]</description>
		<content:encoded><![CDATA[<p>[&#8230;] Try/Catch Blocks Can Hurt Performance Significantly - The Try/Catch performance debate continues&#8230; [&#8230;]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chinh Do</title>
		<link>http://www.chinhdo.com/20080226/try-catch-blocks-performance/#comment-2977</link>
		<dc:creator>Chinh Do</dc:creator>
		<pubDate>Wed, 27 Feb 2008 00:46:40 +0000</pubDate>
		<guid>http://www.chinhdo.com/20080226/try-catch-blocks-performance/#comment-2977</guid>
		<description>Wesner: I am sure "structured exception handling" can be used to refer generically to the try/catch exception handling syntax. Here are some examples from Microsoft: Examples: http://support.microsoft.com/kb/816157, http://support.microsoft.com/kb/315965, &lt;a href="http://msdn2.microsoft.com/en-us/library/aa289505.aspx#vbtchexceptionserrorsinvisualbasicnetanchor2" rel="nofollow"&gt;Intro to Structured Exception Handling&lt;/a&gt;.

I agree with your other points. Bad/inappropriate use of exception handling can lead to performance issues and should be avoided.</description>
		<content:encoded><![CDATA[<p>Wesner: I am sure &#8220;structured exception handling&#8221; can be used to refer generically to the try/catch exception handling syntax. Here are some examples from Microsoft: Examples: <a href="http://support.microsoft.com/kb/816157," rel="nofollow">http://support.microsoft.com/kb/816157,</a> <a href="http://support.microsoft.com/kb/315965," rel="nofollow">http://support.microsoft.com/kb/315965,</a> <a href="http://msdn2.microsoft.com/en-us/library/aa289505.aspx#vbtchexceptionserrorsinvisualbasicnetanchor2" rel="nofollow">Intro to Structured Exception Handling</a>.</p>
<p>I agree with your other points. Bad/inappropriate use of exception handling can lead to performance issues and should be avoided.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Wesner Moise</title>
		<link>http://www.chinhdo.com/20080226/try-catch-blocks-performance/#comment-2975</link>
		<dc:creator>Wesner Moise</dc:creator>
		<pubDate>Wed, 27 Feb 2008 00:28:50 +0000</pubDate>
		<guid>http://www.chinhdo.com/20080226/try-catch-blocks-performance/#comment-2975</guid>
		<description>"Structured exception handling" refers to a specific Win32 OS feature, not the .NET feature...

There is no cost to using try/catch within loops or anywhere else, other than the loss of inlining opportunities.

Costs only arise when exceptions are raised. As a general rule, you should not be relying on exceptions for normal programming tasks. Exceptions are generally for exceptional events, and take up orders of magnitude even outside loops because of stack walking and a variety of other activities.

You had multiple options that avoided the use of exceptions:
1) Use TryGetValue
2) Use ContainsKey</description>
		<content:encoded><![CDATA[<p>&#8220;Structured exception handling&#8221; refers to a specific Win32 OS feature, not the .NET feature&#8230;</p>
<p>There is no cost to using try/catch within loops or anywhere else, other than the loss of inlining opportunities.</p>
<p>Costs only arise when exceptions are raised. As a general rule, you should not be relying on exceptions for normal programming tasks. Exceptions are generally for exceptional events, and take up orders of magnitude even outside loops because of stack walking and a variety of other activities.</p>
<p>You had multiple options that avoided the use of exceptions:<br />
1) Use TryGetValue<br />
2) Use ContainsKey</p>
]]></content:encoded>
	</item>
</channel>
</rss>
