Search code examples
c#.netexceptioncsc

What compiler make with try-catch block


I wonder what CSC compiler make with TRY-CATCH block. For example what compiler will do with code like below?
Will compiler change base code to other form of C# code, before compilation to MSIL? Can I preview this code? What is rules of compiler to work with TRY-CATCH block?

try
{
    int x =45;
    var obj = new MyObject(++x);
    obj.MyMethod(1234, "qwerty");
    short result = x / obj.Function(x);
}
catch(Exception ex)
{
    Console.Writeline(@"Something goes wrong :/");
}

Solution

  • Have a look at this article for details:

    Compiler Internals - How Try/Catch/Throw are Interpreted by the Microsoft Compiler