[Mono-bugs] [Bug 79452][Wis] New - rethrow loses stack trace information

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Wed Sep 20 11:42:43 EDT 2006


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by rodrigobamboo at gmail.com.

http://bugzilla.ximian.com/show_bug.cgi?id=79452

--- shadow/79452	2006-09-20 11:42:43.000000000 -0400
+++ shadow/79452.tmp.1357	2006-09-20 11:42:43.000000000 -0400
@@ -0,0 +1,77 @@
+Bug#: 79452
+Product: Mono: Runtime
+Version: 1.1
+OS: 
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Wishlist
+Component: debug
+AssignedTo: martin at ximian.com                            
+ReportedBy: rodrigobamboo at gmail.com               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: rethrow loses stack trace information
+
+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.");
+        }
+    }
+}


More information about the mono-bugs mailing list