<?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</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>Wed, 01 Feb 2012 12:26:01 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Jarmo</title>
		<link>http://www.chinhdo.com/20080226/try-catch-blocks-performance/comment-page-1/#comment-83884</link>
		<dc:creator>Jarmo</dc:creator>
		<pubDate>Fri, 24 Dec 2010 13:53:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.chinhdo.com/20080226/try-catch-blocks-performance/#comment-83884</guid>
		<description>I was curious about try-catch penalty, and I found this page, but it did not clearly told me is there a penalty or not. I wrote code to prove.

System.DateTime start = System.DateTime.Now;
// 100 million times
for( int index = 0; index &lt; 100000000; ++index)
{
	try
	{
		int x = index;
	}
	catch( System.Exception )
	{
	}
	finally { }
}
System.DateTime end = System.DateTime.Now;
double elapsed = (end - start).TotalMilliseconds;

250ms without try-catch-finally
484ms with try-catch
875ms with try-catch-finally
750ms with try-finally

I can now relax and write try-catch. Of course I use it only for exceptions, which occur seldomly.</description>
		<content:encoded><![CDATA[<p>I was curious about try-catch penalty, and I found this page, but it did not clearly told me is there a penalty or not. I wrote code to prove.</p>
<p>System.DateTime start = System.DateTime.Now;<br />
// 100 million times<br />
for( int index = 0; index &lt; 100000000; ++index)<br />
{<br />
	try<br />
	{<br />
		int x = index;<br />
	}<br />
	catch( System.Exception )<br />
	{<br />
	}<br />
	finally { }<br />
}<br />
System.DateTime end = System.DateTime.Now;<br />
double elapsed = (end &#8211; start).TotalMilliseconds;</p>
<p>250ms without try-catch-finally<br />
484ms with try-catch<br />
875ms with try-catch-finally<br />
750ms with try-finally</p>
<p>I can now relax and write try-catch. Of course I use it only for exceptions, which occur seldomly.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Boigohegeapem</title>
		<link>http://www.chinhdo.com/20080226/try-catch-blocks-performance/comment-page-1/#comment-82053</link>
		<dc:creator>Boigohegeapem</dc:creator>
		<pubDate>Sun, 14 Nov 2010 08:13:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.chinhdo.com/20080226/try-catch-blocks-performance/#comment-82053</guid>
		<description>&lt;a href=&quot;http://livegreenlivesmart.org/members/KamaSutra-Intensity-Condoms-KamaSutra-Intensity-Condoms-7.aspx&quot; rel=&quot;nofollow&quot;&gt;KamaSutra Intensity Condoms KamaSutra Intensity Condoms 7&lt;/a&gt; stiff neck side effect cymbalta &lt;a href=&quot;http://livegreenlivesmart.org/members/how-to-buy-Eulexin-prescription-6.aspx&quot; rel=&quot;nofollow&quot;&gt;how to buy Eulexin prescription 6&lt;/a&gt; medications augmentin long term &lt;a href=&quot;http://livegreenlivesmart.org/members/Aricept-Aricept-5.aspx&quot; rel=&quot;nofollow&quot;&gt;Aricept Aricept 5&lt;/a&gt; combining wellbutrin and lexapro &lt;a href=&quot;http://livegreenlivesmart.org/members/buy-cheap-Avapro-6.aspx&quot; rel=&quot;nofollow&quot;&gt;buy cheap Avapro 6&lt;/a&gt; caffeine hyperactivity &lt;a href=&quot;http://livegreenlivesmart.org/members/generic-Betnovate-fedex-4.aspx&quot; rel=&quot;nofollow&quot;&gt;generic Betnovate fedex 4&lt;/a&gt; viagra 100mg tablets &lt;a href=&quot;http://livegreenlivesmart.org/members/purchase-Lisinopril-online-5.aspx&quot; rel=&quot;nofollow&quot;&gt;purchase Lisinopril online 5&lt;/a&gt; imitrex interaction &lt;a href=&quot;http://livegreenlivesmart.org/members/buy-Levaquin-online-without-a-prescription-3.aspx&quot; rel=&quot;nofollow&quot;&gt;buy Levaquin online without a prescription 3&lt;/a&gt; glyburide micro 3m &lt;a href=&quot;http://livegreenlivesmart.org/members/generic-Glyset-online-canada-7.aspx&quot; rel=&quot;nofollow&quot;&gt;generic Glyset online canada 7&lt;/a&gt; who makes lithium carbonate &lt;a href=&quot;http://livegreenlivesmart.org/members/online-us-pharmacy-Emsam-6.aspx&quot; rel=&quot;nofollow&quot;&gt;online us pharmacy Emsam 6&lt;/a&gt; blackburn bike light lithium x8 &lt;a href=&quot;http://livegreenlivesmart.org/members/Hytrin-saturday-delivery-2.aspx&quot; rel=&quot;nofollow&quot;&gt;Hytrin saturday delivery 2&lt;/a&gt; symptom relief and bactrim 
&lt;a href=&quot;http://livegreenlivesmart.org/members/cheapest-prices-for-Advair-Diskus-online-2.aspx&quot; rel=&quot;nofollow&quot;&gt;cheapest prices for Advair Diskus online 2&lt;/a&gt; lasix and potassium &lt;a href=&quot;http://livegreenlivesmart.org/members/online-Kamagra-Oral-Jelly-sales-3.aspx&quot; rel=&quot;nofollow&quot;&gt;online Kamagra Oral Jelly sales 3&lt;/a&gt; ganeric viagra &lt;a href=&quot;http://livegreenlivesmart.org/members/how-to-buy-Eulexin-prescription-6.aspx&quot; rel=&quot;nofollow&quot;&gt;how to buy Eulexin prescription 6&lt;/a&gt; mood stabilizers depakote &lt;a href=&quot;http://livegreenlivesmart.org/members/Indocin-overnight-5.aspx&quot; rel=&quot;nofollow&quot;&gt;Indocin overnight 5&lt;/a&gt; tropical ketoconazole cream &lt;a href=&quot;http://livegreenlivesmart.org/members/Keppra-cheap-cod-5.aspx&quot; rel=&quot;nofollow&quot;&gt;Keppra cheap cod 5&lt;/a&gt; spontaneious orgasm paxil &lt;a href=&quot;http://livegreenlivesmart.org/members/Allopurinol-cheap-next-day-8.aspx&quot; rel=&quot;nofollow&quot;&gt;Allopurinol cheap next day 8&lt;/a&gt; how to dispense clonidine for toddler &lt;a href=&quot;http://livegreenlivesmart.org/members/Coreg-without-presciption-1.aspx&quot; rel=&quot;nofollow&quot;&gt;Coreg without presciption 1&lt;/a&gt; aciphex for heartburn &lt;a href=&quot;http://livegreenlivesmart.org/members/Grifulvin-V-drug-4.aspx&quot; rel=&quot;nofollow&quot;&gt;Grifulvin V drug 4&lt;/a&gt; side effects of cefuroxime axetil &lt;a href=&quot;http://livegreenlivesmart.org/members/non-prescription-Furosemide-alternative-9.aspx&quot; rel=&quot;nofollow&quot;&gt;non prescription Furosemide alternative 9&lt;/a&gt; topamax assistance program &lt;a href=&quot;http://livegreenlivesmart.org/members/buying-Citalopram-2.aspx&quot; rel=&quot;nofollow&quot;&gt;buying Citalopram 2&lt;/a&gt; effect of finasteride</description>
		<content:encoded><![CDATA[<p><a href="http://livegreenlivesmart.org/members/KamaSutra-Intensity-Condoms-KamaSutra-Intensity-Condoms-7.aspx" rel="nofollow">KamaSutra Intensity Condoms KamaSutra Intensity Condoms 7</a> stiff neck side effect cymbalta <a href="http://livegreenlivesmart.org/members/how-to-buy-Eulexin-prescription-6.aspx" rel="nofollow">how to buy Eulexin prescription 6</a> medications augmentin long term <a href="http://livegreenlivesmart.org/members/Aricept-Aricept-5.aspx" rel="nofollow">Aricept Aricept 5</a> combining wellbutrin and lexapro <a href="http://livegreenlivesmart.org/members/buy-cheap-Avapro-6.aspx" rel="nofollow">buy cheap Avapro 6</a> caffeine hyperactivity <a href="http://livegreenlivesmart.org/members/generic-Betnovate-fedex-4.aspx" rel="nofollow">generic Betnovate fedex 4</a> viagra 100mg tablets <a href="http://livegreenlivesmart.org/members/purchase-Lisinopril-online-5.aspx" rel="nofollow">purchase Lisinopril online 5</a> imitrex interaction <a href="http://livegreenlivesmart.org/members/buy-Levaquin-online-without-a-prescription-3.aspx" rel="nofollow">buy Levaquin online without a prescription 3</a> glyburide micro 3m <a href="http://livegreenlivesmart.org/members/generic-Glyset-online-canada-7.aspx" rel="nofollow">generic Glyset online canada 7</a> who makes lithium carbonate <a href="http://livegreenlivesmart.org/members/online-us-pharmacy-Emsam-6.aspx" rel="nofollow">online us pharmacy Emsam 6</a> blackburn bike light lithium x8 <a href="http://livegreenlivesmart.org/members/Hytrin-saturday-delivery-2.aspx" rel="nofollow">Hytrin saturday delivery 2</a> symptom relief and bactrim<br />
<a href="http://livegreenlivesmart.org/members/cheapest-prices-for-Advair-Diskus-online-2.aspx" rel="nofollow">cheapest prices for Advair Diskus online 2</a> lasix and potassium <a href="http://livegreenlivesmart.org/members/online-Kamagra-Oral-Jelly-sales-3.aspx" rel="nofollow">online Kamagra Oral Jelly sales 3</a> ganeric viagra <a href="http://livegreenlivesmart.org/members/how-to-buy-Eulexin-prescription-6.aspx" rel="nofollow">how to buy Eulexin prescription 6</a> mood stabilizers depakote <a href="http://livegreenlivesmart.org/members/Indocin-overnight-5.aspx" rel="nofollow">Indocin overnight 5</a> tropical ketoconazole cream <a href="http://livegreenlivesmart.org/members/Keppra-cheap-cod-5.aspx" rel="nofollow">Keppra cheap cod 5</a> spontaneious orgasm paxil <a href="http://livegreenlivesmart.org/members/Allopurinol-cheap-next-day-8.aspx" rel="nofollow">Allopurinol cheap next day 8</a> how to dispense clonidine for toddler <a href="http://livegreenlivesmart.org/members/Coreg-without-presciption-1.aspx" rel="nofollow">Coreg without presciption 1</a> aciphex for heartburn <a href="http://livegreenlivesmart.org/members/Grifulvin-V-drug-4.aspx" rel="nofollow">Grifulvin V drug 4</a> side effects of cefuroxime axetil <a href="http://livegreenlivesmart.org/members/non-prescription-Furosemide-alternative-9.aspx" rel="nofollow">non prescription Furosemide alternative 9</a> topamax assistance program <a href="http://livegreenlivesmart.org/members/buying-Citalopram-2.aspx" rel="nofollow">buying Citalopram 2</a> effect of finasteride</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ian</title>
		<link>http://www.chinhdo.com/20080226/try-catch-blocks-performance/comment-page-1/#comment-80797</link>
		<dc:creator>Ian</dc:creator>
		<pubDate>Fri, 01 Oct 2010 17:00:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.chinhdo.com/20080226/try-catch-blocks-performance/#comment-80797</guid>
		<description>If you are for example iterating a list of 100,000 items, and out of that list, perhaps you may encounter 1 or exception situations, would it be more performant to do an if check 100,000 times, or to remove the if check, and allow your exception block to handle the &#039;exceptional situation&#039;, say perhaps a null reference or something?</description>
		<content:encoded><![CDATA[<p>If you are for example iterating a list of 100,000 items, and out of that list, perhaps you may encounter 1 or exception situations, would it be more performant to do an if check 100,000 times, or to remove the if check, and allow your exception block to handle the &#8216;exceptional situation&#8217;, say perhaps a null reference or something?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: [Перевод] Лучшие практические решения обработки исключений в веб-приложениях ASP.NET - Александр Гончарук - технический блог - Microsoft User Group Винн</title>
		<link>http://www.chinhdo.com/20080226/try-catch-blocks-performance/comment-page-1/#comment-78795</link>
		<dc:creator>[Перевод] Лучшие практические решения обработки исключений в веб-приложениях ASP.NET - Александр Гончарук - технический блог - Microsoft User Group Винн</dc:creator>
		<pubDate>Sat, 19 Jun 2010 17:37:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.chinhdo.com/20080226/try-catch-blocks-performance/#comment-78795</guid>
		<description>[...] Try/Catch Blocks Can Hurt Performance Significantly - Chinh Do [...]</description>
		<content:encoded><![CDATA[<p>[...] Try/Catch Blocks Can Hurt Performance Significantly &#8211; Chinh Do [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Using JavaScript&#8217;s Try-Catch Statement &#124; 610 Design</title>
		<link>http://www.chinhdo.com/20080226/try-catch-blocks-performance/comment-page-1/#comment-78040</link>
		<dc:creator>Using JavaScript&#8217;s Try-Catch Statement &#124; 610 Design</dc:creator>
		<pubDate>Thu, 08 Apr 2010 10:48:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.chinhdo.com/20080226/try-catch-blocks-performance/#comment-78040</guid>
		<description>[...] short answer seems to be yes, although this article on MSDN says that performance is affected only when the catch portion [...]</description>
		<content:encoded><![CDATA[<p>[...] short answer seems to be yes, although this article on MSDN says that performance is affected only when the catch portion [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Using JavaScript&#8217;s Try-Catch Statement &#124; Impressive Webs Toronto</title>
		<link>http://www.chinhdo.com/20080226/try-catch-blocks-performance/comment-page-1/#comment-78007</link>
		<dc:creator>Using JavaScript&#8217;s Try-Catch Statement &#124; Impressive Webs Toronto</dc:creator>
		<pubDate>Tue, 06 Apr 2010 14:48:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.chinhdo.com/20080226/try-catch-blocks-performance/#comment-78007</guid>
		<description>[...] short answer seems to be yes, although this article on MSDN says that performance is affected only when the catch portion [...]</description>
		<content:encoded><![CDATA[<p>[...] short answer seems to be yes, although this article on MSDN says that performance is affected only when the catch portion [...]</p>
]]></content:encoded>
	</item>
	<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>
</channel>
</rss>

