Some Creativity

Weblog of Siddharth Uppal

Archive for April 29th, 2008

Two (useless but potentially) interesting tid-bits

without comments

Try-Catch-Finally

A try-catch-finally is converted into IL by the C# compiler as a try-catch inside the try block of another try-finally. This allows for finally block to execute even when exceptions are raised in the catch block. Use ildasm and check it out yourself!

throw football;

Though you cannot throw an arbitrary managed object as “throw myObj” (you’ll get a compilation error), you can modify the generated IL to do so. However your catch block will actually receive a RuntimeWrappedException in these scenarios. Why is this allowed? Well, unlike C#, it is legal to throw arbitrary objects in managed C++ and in those cases a RuntimeWrappedException is thrown too.

Written by Sid

April 29th, 2008 at 10:17 pm

Posted in .NET, General, Tech/Hacks

Tagged with , ,