Bugzilla – Bug 322158
rethrow loses stack trace information
Last modified: 2010-10-04 00:11:10 UTC
---- Reported by rodrigobamboo@gmail.com 2006-09-20 11:42:43 MST ---- namespace BugReport { using System; class Foo { public static void Bar() { throw new ApplicationException("oh"); } } class Program { static void Main(string[] args) { try { FooBar(); } catch (Exception x) { Assert(-1 != x.StackTrace.IndexOf("BugReport.Program.Main")); } try { ReThrowFooBar(); } catch (Exception x) { Assert(-1 != x.StackTrace.IndexOf("BugReport.Program.Main")); } } static void FooBar() { Foo.Bar(); } static void ReThrowFooBar() { try { Foo.Bar(); } catch (Exception) { throw; // <--- ms.net preserves stack trace here } } static void Assert(bool condition) { if (condition) return; throw new ApplicationException("Assertion failed."); } } } ---- Additional Comments From vargaz@gmail.com 2006-09-20 12:12:34 MST ---- This is a known bug, it is a bit hard to figure out what part of the stack trace to preserve in some situations. ---- Additional Comments From joe@otee.dk 2006-09-21 17:34:27 MST ---- Would be really useful to get fixed even though it's hard. Stacktraces are pretty important when developing code. Especially in boo (and the derived unityscript), this means most of the duck typed code will lose the important part of the stacktrace, so when you encounter an error, you have no clue where it happened. ---- Additional Comments From vargaz@gmail.com 2006-09-22 05:29:44 MST ---- We would fix it but don't know how to. For example, under MS, if I print the stack trace in ReThrowFooBar (), it doesn't include the Main method, but when I print it out in Main, it does. So we _do_ preserve the stack trace, while MS changes it during a rethrow. ---- Additional Comments From rodrigobamboo@gmail.com 2006-09-22 08:30:33 MST ---- "For example, under MS, if I print the stack trace in ReThrowFooBar (), it doesn't include the Main method, but when I print it out in Main, it does." That's ok. An exception stack trace should include stack trace information upto the method which handles it. "So we _do_ preserve the stack trace, while MS changes it during a rethrow." Interesting. Would it be possible to append stack trace information during a rethrow to match the clr behavior then? If it does not seem doable, would someone be kind enough to provide some pointers on why and where to look in the source code to try to come up with a patch? This bug blocked bug(s) 71375. Unknown operating system unknown. Setting to default OS "Other".
Old.
It is old, but it is a pretty valid bug.
Created attachment 348292 [details] test case for rethrow bug
This is a huge bug in the system: For the attached code, mono prints out: STACK bar at ExceptionTest.A.bar () [0x00000] in /home/strangeloop/ExceptionTest/Main.cs:23 STACK baz at ExceptionTest.A.bar () [0x00000] in /home/strangeloop/ExceptionTest/Main.cs:23 From Windows C#: STACK bar at ExceptionTest.A.foo() in C:\Users\Administrator\Desktop\etest\ExceptionTest\Main.cs:line 18 at ExceptionTest.A.bar() in C:\Users\Administrator\Desktop\etest\ExceptionTest\Main.cs:line 23 STACK baz at ExceptionTest.A.foo() in C:\Users\Administrator\Desktop\etest\ExceptionTest\Main.cs:line 18 at ExceptionTest.A.bar() in C:\Users\Administrator\Desktop\etest\ExceptionTest\Main.cs:line 28 at ExceptionTest.A.baz() in C:\Users\Administrator\Desktop\etest\ExceptionTest\Main.cs:line 34 I will also note that if the code is changed to do "throw e;" instead of just "throw;" the output also varies. This is affecting our ability to debug problems on production systems.
Whoops put severity too high
*** Bug 643371 has been marked as a duplicate of this bug. ***