The code below generates different exception stack trace in both debug and release mode:
static class ET
{
public static void E1()
{
throw new Exception("E1");
}
public static void E2()
{
try
{
E1();
}
catch (Exception e)
{
throw;
}
}
public static void Entry()
{
try
{
E2();
}
catch (Exception e)
{
Console.WriteLine(e.StackTrace);
}
}
}
Result in Debug Mode:
at ET.E1() in D:\myStudio\CSharp\CSharp4.0\MyCSharp\ExceptionHandling.cs:line 47
at ET.E2() in D:\myStudio\CSharp\CSharp4.0\MyCSharp\ExceptionHandling.cs:line 58
at ET.Entry() in D:\myStudio\CSharp\CSharp4.0\MyCSharp\ExceptionHandling.cs:line 68
Result in Release Mode:
at ET.E2() in D:\myStudio\CSharp\CSharp4.0\MyCSharp\ExceptionHandling.cs:line 55
at ET.Entry() in D:\myStudio\CSharp\CSharp4.0\MyCSharp\ExceptionHandling.cs:line 68
Please note that the first line from the result in Release mode is missing. How to return the offending line in release mode.
You are probably seeing the result of inlining. When you compile in debug mode, inlining is always turned off (so that debugging makes sense). When you compile in release mode, the compiler will remove certain methods (subject to a lot of rules) and insert their content into all of the call sites. This improves the overall performance of those methods by removing the method call overhead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With