<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Exception Cost: When to throw and when not to</title><link>http://blogs.msdn.com/ricom/archive/2003/12/19/44697.aspx</link><description>The Cost of Exceptions I wish I could speak intelligently on the exact cost but it's really quite difficult to project for any given usage, it's best measured for your specific cases. However there are a couple of different kinds of cost and they're both</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: Exception Cost: When to throw and when not to</title><link>http://blogs.msdn.com/ricom/archive/2003/12/19/44697.aspx#44705</link><pubDate>Fri, 19 Dec 2003 21:39:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:44705</guid><dc:creator>Jim Argeropoulos</dc:creator><description>You said:&lt;br&gt;  In the managed world, there isn't this&lt;br&gt;  widespread notion of deterministic &lt;br&gt;  destruction of objects.  This means that&lt;br&gt;  the static cost of exceptions can be quite&lt;br&gt;  a bit lower,&lt;br&gt;&lt;br&gt;Seeing that the new Managed C++/CLI coming in Whidbey will have deterministic finalization, will it return to the same level of cost as standard C++?</description></item><item><title>re: Exception Cost: When to throw and when not to</title><link>http://blogs.msdn.com/ricom/archive/2003/12/19/44697.aspx#44707</link><pubDate>Fri, 19 Dec 2003 21:50:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:44707</guid><dc:creator>Jim Argeropoulos</dc:creator><description>In managed C++ I used to use stack based objects to avoid try/catch blocks when possible. The code was cleaner and there was no explicit set up of the try catch which was faster.&lt;br&gt;&lt;br&gt;I now use a &amp;quot;using&amp;quot; when possible instead, and you mention that there is an associated try catch with it. I guess I knew that there was a try/catch underneath, but somehow I didn't want to admit it to myself. A bit disappointing that I only have cleaner and more reusable code with a &amp;quot;using&amp;quot;. Ah, well. It is nice to have the feature.</description></item><item><title>re: Exception Cost: When to throw and when not to</title><link>http://blogs.msdn.com/ricom/archive/2003/12/19/44697.aspx#44712</link><pubDate>Fri, 19 Dec 2003 22:06:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:44712</guid><dc:creator>Rico Mariani</dc:creator><description>Yes, deterministic destruction would increase the cost to the standard level.  Naturally we're always trying to find clever ways to keep that to a minimum but even low(er) cost is more than none at all.</description></item><item><title>re: Exception Cost: When to throw and when not to</title><link>http://blogs.msdn.com/ricom/archive/2003/12/19/44697.aspx#44721</link><pubDate>Fri, 19 Dec 2003 22:28:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:44721</guid><dc:creator>John Cavnar-Johnson</dc:creator><description>So, do you think you could speak to the folks who designed System.Messaging? That namespace abuses exceptions in the most horrific ways. For example, if you call a synchronous Receive or Peek method on a MessageQueue and you specify a timeout value, the object raises an exception when your timeout expires.  That would be bad enough (raising an exception for an outcome that I actually asked for), but it raises the SAME exception for everything, forcing me to interrogate the MessageQueueErrorCode to distinguish between the expected result (the timeout) and all the real exceptional situations that might have occurred.  Luckily for me, I use VB.NET, so I can use the &amp;quot;Catch ... When&amp;quot; syntax.  I pity the poor C# coders who have to deal with this crap.</description></item><item><title>Rico on Managed Exception Costs</title><link>http://blogs.msdn.com/ricom/archive/2003/12/19/44697.aspx#44722</link><pubDate>Fri, 19 Dec 2003 22:29:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:44722</guid><dc:creator>Ken Brubaker</dc:creator><description /></item><item><title>re: Exception Cost: When to throw and when not to</title><link>http://blogs.msdn.com/ricom/archive/2003/12/19/44697.aspx#44724</link><pubDate>Fri, 19 Dec 2003 22:31:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:44724</guid><dc:creator>Rico Mariani</dc:creator><description>Sadly, I have a very long list of people to speak to...</description></item><item><title>re: Exception Cost: When to throw and when not to</title><link>http://blogs.msdn.com/ricom/archive/2003/12/19/44697.aspx#44726</link><pubDate>Fri, 19 Dec 2003 22:36:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:44726</guid><dc:creator>David Levine</dc:creator><description>The hidden exception usage case is a little misleading. When using try-finally constructs and flow control leaves the try block normally (i.e. no exception occurred) then you do not incur the overhead of the SEH stack walk that you would get had an exception been thrown and the finally block was executed on the 2nd pass as the stack was being unwound via a global unwind. There may be some overhead if bookkeeping is done to tables tracking the state of objects within the body of the method. &lt;br&gt;&lt;br&gt;I'd be interested in how much overhead there is in a try-finally where an exception does not occur. It should be very low.&lt;br&gt;</description></item><item><title>re: Exception Cost: When to throw and when not to</title><link>http://blogs.msdn.com/ricom/archive/2003/12/19/44697.aspx#44727</link><pubDate>Fri, 19 Dec 2003 22:40:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:44727</guid><dc:creator>Rico Mariani</dc:creator><description>You are correct, in the normal case with the finally block and no exception all that has to happen is a fairly minor state change to indicate that the finally block need not be run.  However it's not nothing and such state changes do add up.  &lt;br&gt;&lt;br&gt;In unmananged code you could think of each destructor as being in its own implicit finally block and you wouldn't be too far from the truth.  &lt;br&gt;&lt;br&gt;The fact that these implicit finally blocks can be absent in the managed world helps reduce the static cost.</description></item><item><title>re: Exception Cost: When to throw and when not to</title><link>http://blogs.msdn.com/ricom/archive/2003/12/19/44697.aspx#44730</link><pubDate>Fri, 19 Dec 2003 22:48:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:44730</guid><dc:creator>Rico Mariani</dc:creator><description>By the way, I'd just like to say how much I appreciate the thoughtful comments and clarifications that my readers are making.&lt;br&gt;&lt;br&gt;Thank you very much guys, it really helps the overall quality of the blog a lot.  Even if it does mean a little egg on the face for me sometimes :)&lt;br&gt;&lt;br&gt;Greater good and all that :)</description></item><item><title>re: Exception Cost: When to throw and when not to</title><link>http://blogs.msdn.com/ricom/archive/2003/12/19/44697.aspx#44732</link><pubDate>Fri, 19 Dec 2003 23:02:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:44732</guid><dc:creator>RichB</dc:creator><description>We all appreciate the quality of your blog. That's why you're the #4 hit on Google for 'rico'.</description></item><item><title>re: Exception Cost: When to throw and when not to</title><link>http://blogs.msdn.com/ricom/archive/2003/12/19/44697.aspx#44850</link><pubDate>Sat, 20 Dec 2003 18:08:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:44850</guid><dc:creator>Frank Hileman</dc:creator><description>We have been hit by exception overhead in a couple MS APIs.&lt;br&gt;&lt;br&gt;System.Drawing routinely throws exceptions, which are often impossible to predict. Put a few hundred of these in a tight display loop... it becomes horrible. One example, is an extreme zoomout matrix, when displaying text. Throws an exception, but to predict when? Nearly impossible.&lt;br&gt;&lt;br&gt;The DTE api (the VS automation object model) usually throws an exception to indicate an object cannot be found in a collection. Simply looking up a control on a command bar can throw an exception. This has also caused perf hits for us.&lt;br&gt;&lt;br&gt;Thanks for the focus on this widespread problem! I hope it will lead to some changes in the MS libraries.</description></item><item><title>re: Exception Cost: When to throw and when not to</title><link>http://blogs.msdn.com/ricom/archive/2003/12/19/44697.aspx#45191</link><pubDate>Mon, 22 Dec 2003 23:57:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:45191</guid><dc:creator>Dmitriy Zaslavskiy</dc:creator><description>As per Chris Brumme's note: There is also a cost related to the fact the some optimization are not being performed by JIT in the presents of catch</description></item><item><title>Fun with VB .NET and Managed C++</title><link>http://blogs.msdn.com/ricom/archive/2003/12/19/44697.aspx#47826</link><pubDate>Tue, 06 Jan 2004 07:15:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:47826</guid><dc:creator>Ramblings of a Code Monkey</dc:creator><description>Unfortunately, it looks like both the FindFirstFile()/FindNextFile method that I mentioned &amp;quot;&amp;gt;yesterday and Richard's #003900&amp;quot;&amp;gt;VB .NET suggestionDir() really just calls the Win32 API functions behind the scenes). In both cases, when the code is looking for all of the subdirectories...</description></item><item><title>If you think it will be at all normal for anyone to want to catch your exception, then probably it shouldn't be an exception at all.</title><link>http://blogs.msdn.com/ricom/archive/2003/12/19/44697.aspx#75252</link><pubDate>Wed, 18 Feb 2004 05:24:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:75252</guid><dc:creator>Edgar S</dc:creator><description /></item><item><title>re: Exception Cost: When to throw and when not to</title><link>http://blogs.msdn.com/ricom/archive/2003/12/19/44697.aspx#142925</link><pubDate>Thu, 27 May 2004 07:20:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:142925</guid><dc:creator>Me</dc:creator><description>I guess myself the reason of such a big cost when throwing an exception.</description></item><item><title>When to create exception objects</title><link>http://blogs.msdn.com/ricom/archive/2003/12/19/44697.aspx#181214</link><pubDate>Tue, 13 Jul 2004 03:11:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:181214</guid><dc:creator>Rico Mariani's WebLog</dc:creator><description /></item><item><title>Exceptions</title><link>http://blogs.msdn.com/ricom/archive/2003/12/19/44697.aspx#182059</link><pubDate>Tue, 13 Jul 2004 23:28:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:182059</guid><dc:creator>Bryan's Blog</dc:creator><description /></item><item><title>re: Qualitative Code Differences in Managed Code</title><link>http://blogs.msdn.com/ricom/archive/2003/12/19/44697.aspx#378483</link><pubDate>Wed, 23 Feb 2005 04:07:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:378483</guid><dc:creator>Rico Mariani's Performance Tidbits</dc:creator><description /></item><item><title>re: Common Sources of Processor Performance Penalties: Five Issues</title><link>http://blogs.msdn.com/ricom/archive/2003/12/19/44697.aspx#385719</link><pubDate>Sat, 05 Mar 2005 09:35:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:385719</guid><dc:creator>Rico Mariani's Performance Tidbits</dc:creator><description /></item><item><title>re: Common Sources of Processor Performance Penalties: Five Issues</title><link>http://blogs.msdn.com/ricom/archive/2003/12/19/44697.aspx#385721</link><pubDate>Sat, 05 Mar 2005 09:37:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:385721</guid><dc:creator>Rico Mariani's Performance Tidbits</dc:creator><description /></item><item><title>The True Cost of .NET Exceptions</title><link>http://blogs.msdn.com/ricom/archive/2003/12/19/44697.aspx#754662</link><pubDate>Thu, 14 Sep 2006 23:41:10 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:754662</guid><dc:creator>Rico Mariani's Performance Tidbits</dc:creator><description>Here's an article under Jon's Homepage that was just brought to my attention.&amp;amp;amp;nbsp; It's an interesting...</description></item><item><title>Performance Guideline: Use TryParse Method to Avoid Unnecessary Exceptions</title><link>http://blogs.msdn.com/ricom/archive/2003/12/19/44697.aspx#792773</link><pubDate>Thu, 05 Oct 2006 06:28:13 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:792773</guid><dc:creator>J.D. Meier's Blog</dc:creator><description>&lt;p&gt;Prashant Bansode, Bhavin Raichura, and Girisha Gadikere teamed up with Claudio Caldato (CLR team) to&lt;/p&gt;
</description></item><item><title>Still Learning  &amp;raquo; Blog Archive   &amp;raquo; Exception vs. Error Codes in C++</title><link>http://blogs.msdn.com/ricom/archive/2003/12/19/44697.aspx#6946415</link><pubDate>Wed, 02 Jan 2008 05:26:20 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6946415</guid><dc:creator>Still Learning  » Blog Archive   » Exception vs. Error Codes in C++</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://imehta.com/blog-ketan/?p=15"&gt;http://imehta.com/blog-ketan/?p=15&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>Is your app trying to tell you something?</title><link>http://blogs.msdn.com/ricom/archive/2003/12/19/44697.aspx#9506525</link><pubDate>Wed, 25 Mar 2009 08:52:59 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9506525</guid><dc:creator>Ahmeds' Random Expressions</dc:creator><description>&lt;p&gt;Exceptions (unexpected errors) are a part of every application lifecycle. No matter how reliable your&lt;/p&gt;
</description></item></channel></rss>