<?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>Return vs. Finally (2)</title><link>http://blogs.msdn.com/jmstall/archive/2007/12/16/return-vs-finally-2.aspx</link><description>The Return statement and finally have competition. Both can are the "last" thing to execute when a function exits, so which of them is really last? I blogged about this before regarding C#'s semantics setting data. Now I'll compare some interesting differences</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: Return vs. Finally (2)</title><link>http://blogs.msdn.com/jmstall/archive/2007/12/16/return-vs-finally-2.aspx#6787354</link><pubDate>Mon, 17 Dec 2007 11:39:17 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6787354</guid><dc:creator>.NET Junkie</dc:creator><description>&lt;p&gt;I'm very curious. How does the IL look like that IronPython generates?&lt;/p&gt;</description></item><item><title>re: Return vs. Finally (2)</title><link>http://blogs.msdn.com/jmstall/archive/2007/12/16/return-vs-finally-2.aspx#6787842</link><pubDate>Mon, 17 Dec 2007 12:55:50 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6787842</guid><dc:creator>Niki</dc:creator><description>&lt;p&gt;Python: return self.i++&lt;/p&gt;
&lt;p&gt;class Sample:&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;def meth(self):&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;try:&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return self.i&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;finally:&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;self.i += 1&lt;/p&gt;</description></item><item><title>re: Return vs. Finally (2)</title><link>http://blogs.msdn.com/jmstall/archive/2007/12/16/return-vs-finally-2.aspx#6787885</link><pubDate>Mon, 17 Dec 2007 13:01:22 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6787885</guid><dc:creator>StewartT</dc:creator><description>&lt;p&gt;If you treat the IL finally block as the moral equivalent of C++'s automatic destructor calls, then C++ has a hybrid of the two, where it is not possible to return from a &amp;quot;finally&amp;quot; block, since there is no where to put the return statement, however it is possible to throw. In C++ the consensus seems to be that throwing from destructors is a &amp;quot;bad thing&amp;quot;(TM), and I have only ever had cause to do it when writing classes expressly designed to do it as part of dynamic exception generation (don't ask :)). It is particularly dodgy in C++ of course due to the amusing C++ double fault behaviour, where if you throw from a destructor during an exception unwind, std::terminate is called and the process is to all intents and purposes dead, however you cannot know at the time when you throw that this is going to happen.&lt;/p&gt;
&lt;p&gt;I'm not saying its right, but I thought it was another perspective i'd point out.&lt;/p&gt;
</description></item><item><title>re: Return vs. Finally (2)</title><link>http://blogs.msdn.com/jmstall/archive/2007/12/16/return-vs-finally-2.aspx#6791393</link><pubDate>Mon, 17 Dec 2007 21:01:44 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6791393</guid><dc:creator>jmstall</dc:creator><description>&lt;p&gt;Stewart - good point about C++, that would have been good for me to include at the top. &lt;/p&gt;
&lt;p&gt;Niki - yeah, that's another twisted example. That's similar to what I blogged about before, and C# has similar behavior.&lt;/p&gt;
&lt;p&gt;.NET Junkie: basically, you can build a finally block with try/catch blocks + rethrow. &amp;nbsp;It's clunkier, and the stack-unwinding is worse under a debugger/watson, but it gives you much finer control.&lt;/p&gt;
</description></item></channel></rss>