<?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>Quiz: More Exception Mysteries </title><link>http://blogs.msdn.com/brada/archive/2004/10/21/246102.aspx</link><description>Yesterday I heard about a cool Whidbey feature that inspired me to come up with this little quiz. The code below when run will print out: In try In catch After try..catch class Program { static void Main ( string [] args) { try { Console .WriteLine( "In</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: Quiz: More Exception Mysteries </title><link>http://blogs.msdn.com/brada/archive/2004/10/21/246102.aspx#246122</link><pubDate>Fri, 22 Oct 2004 04:04:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:246122</guid><dc:creator>Steve Maine</dc:creator><description>All you have to do is hook the new CatchingException event off the current AppDomain. You can do this without introducing an additional method via anonymous delegates:&lt;br&gt;&lt;br&gt;AppDomain.CurrentDomain.CatchingException += delegate( object o, CatchingExceptionEventArgs a ) &lt;br&gt;            { Console.WriteLine( &amp;quot;Mystery inserted code&amp;quot; ); };&lt;br&gt;&lt;br&gt;</description></item><item><title>re: Quiz: More Exception Mysteries </title><link>http://blogs.msdn.com/brada/archive/2004/10/21/246102.aspx#246132</link><pubDate>Fri, 22 Oct 2004 04:26:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:246132</guid><dc:creator>Nick Wienholt</dc:creator><description>You don't even need to specify the delegates signature - the compiler can infer it, so the following code will work too:&lt;br&gt;&lt;br&gt;AppDomain.CurrentDomain.CatchingException += delegate { Console.WriteLine(&amp;quot;Mystery inserted code&amp;quot;); };</description></item><item><title>re: Quiz: More Exception Mysteries </title><link>http://blogs.msdn.com/brada/archive/2004/10/21/246102.aspx#246150</link><pubDate>Fri, 22 Oct 2004 05:24:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:246150</guid><dc:creator>Robert Kozak</dc:creator><description>Add Console.WriteLine(&amp;quot;Mystery inserted code&amp;quot;); &lt;br&gt;right after Console.WriteLn(&amp;quot;In try&amp;quot;);&lt;br&gt;&lt;br&gt;Only 1 extra line of code. Yeah I know. Im a dork. :-D&lt;br&gt;&lt;br&gt;-- Robert</description></item><item><title>re: Quiz: More Exception Mysteries </title><link>http://blogs.msdn.com/brada/archive/2004/10/21/246102.aspx#246165</link><pubDate>Fri, 22 Oct 2004 06:29:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:246165</guid><dc:creator>Andrei</dc:creator><description>And what is so cool about this feature? The ability to specify cross-cuts as defined in AOP is not implemented in whidbey. I don't see much sense in the registering the fact that exception was thrown. Anyway, instead of SEH's resumable exceptions, CLR doesn't allow to recover from exceptional situation and continue execution from the faulty instruction (without extensive program logic to handle that situation). </description></item><item><title>Quiz.</title><link>http://blogs.msdn.com/brada/archive/2004/10/21/246102.aspx#246178</link><pubDate>Fri, 22 Oct 2004 10:10:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:246178</guid><dc:creator>Di .NET e di altre amenita'</dc:creator><description /></item><item><title>re: Quiz: More Exception Mysteries </title><link>http://blogs.msdn.com/brada/archive/2004/10/21/246102.aspx#246192</link><pubDate>Fri, 22 Oct 2004 07:53:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:246192</guid><dc:creator>Ben Murphy</dc:creator><description>here is my dodgy version, it compiles in mono not sure about csc&lt;br&gt;&lt;br&gt;using System;&lt;br&gt;class Program {&lt;br&gt;    class Exception : System.Exception {&lt;br&gt;        public Exception() {&lt;br&gt;            Console.WriteLine(&amp;quot;Mystery inserted code&amp;quot;);&lt;br&gt;        }&lt;br&gt;    }&lt;br&gt;    static void Main(string[] args) {&lt;br&gt;        try {&lt;br&gt;            Console.WriteLine(&amp;quot;In try&amp;quot;);&lt;br&gt;            throw new Exception();&lt;br&gt;        } catch (Exception) {&lt;br&gt;            Console.WriteLine(&amp;quot;In catch&amp;quot;);&lt;br&gt;        }&lt;br&gt;        Console.WriteLine(&amp;quot;After try..catch&amp;quot;);&lt;br&gt;    }&lt;br&gt;}&lt;br&gt;</description></item><item><title>re: Quiz: More Exception Mysteries </title><link>http://blogs.msdn.com/brada/archive/2004/10/21/246102.aspx#246238</link><pubDate>Fri, 22 Oct 2004 10:58:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:246238</guid><dc:creator>Ernst Kuschke</dc:creator><description>Damn, I was going to do the same as Ben :)</description></item><item><title>re: Quiz: More Exception Mysteries </title><link>http://blogs.msdn.com/brada/archive/2004/10/21/246102.aspx#246239</link><pubDate>Fri, 22 Oct 2004 11:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:246239</guid><dc:creator>mihailik</dc:creator><description>Of course Steve and Nick are right. But Ben's answer is very cool too! :-)</description></item><item><title>re: Quiz: More Exception Mysteries </title><link>http://blogs.msdn.com/brada/archive/2004/10/21/246102.aspx#246249</link><pubDate>Fri, 22 Oct 2004 11:41:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:246249</guid><dc:creator>Raymond Lewallen</dc:creator><description>What Ben wrote was the first thing that came to my mind and was an obvious way to get the desired output, but I think Nick and Steve, who both gave answers I didn't think of, probably have the solution Brad is looking for.</description></item><item><title>re: Quiz: More Exception Mysteries </title><link>http://blogs.msdn.com/brada/archive/2004/10/21/246102.aspx#246308</link><pubDate>Fri, 22 Oct 2004 14:53:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:246308</guid><dc:creator>Keith Patrick</dc:creator><description>Andrei: I can think of several uses for such a feature.  For example, it makes a debugger's implementation of BreakOnException much easier to implement (I'm toying with writing one for some .Net-based scripting support I added to an app of mine).  Also, it can greatly help in those issues like XML deserialization or called to ConfigurationSettings.GetConfig, where exceptions can get thrown very deep in the code and are either masked by returning null (ugh) or wrapped in several layers of exceptions, like ConfigurationSettings is so fond of doing&lt;br&gt;Of course, the downside to this is that you can get burned when folks use exceptions for non-exceptional cases.  IBM's Java Sax parser made it damn-near impossible for me to effectively use BreakOnException in VAJ, because it threw exceptions EVERYWHERE.</description></item><item><title>re: Quiz: More Exception Mysteries </title><link>http://blogs.msdn.com/brada/archive/2004/10/21/246102.aspx#246347</link><pubDate>Fri, 22 Oct 2004 16:12:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:246347</guid><dc:creator>RJ</dc:creator><description>It also might be useful if you just want to do something silly like Debug.WriteLine the full text of every exception thrown; without modifying all your catch blocks to save the full gory details.  Or maybe you don't even own the actual catch block, and don't want to rethrow exceptions everywhere.  But then, I have not RTFM.</description></item><item><title>re: Quiz: More Exception Mysteries </title><link>http://blogs.msdn.com/brada/archive/2004/10/21/246102.aspx#246494</link><pubDate>Fri, 22 Oct 2004 20:36:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:246494</guid><dc:creator>cheater</dc:creator><description>System.out.println(&amp;quot;In try\nMystery inserted code\nIn catch\nAfter try..catch\n&amp;quot;);&lt;br&gt;System.exit(0);</description></item></channel></rss>