Bug 7524 - Rethrow exception truncates stacktrace
Summary: Rethrow exception truncates stacktrace
Status: RESOLVED FIXED
Alias: None
Product: Runtime
Classification: Mono
Component: General ()
Version: unspecified
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Alexander Kyte
URL:
Depends on:
Blocks:
 
Reported: 2012-09-28 08:23 UTC by Sebastian Krysmanski
Modified: 2015-06-22 11:47 UTC (History)
4 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Sebastian Krysmanski 2012-09-28 08:23:40 UTC
Using "throw;" in MonoDroid truncates the stacktrace (like "throw excpt;" does). However, in .NET this statement is provided to not(!) truncate the stacktrace.

Assume the following code:

    void DoTest() {
      try {
        Test1();
      }
      catch (Exception e) {
        Console.WriteLine(e.ToString());
      }
    }

    private void Test1() {
      try {
        Test2();
      }
      catch (Exception e) {
        if (e.Message == "Test2") { // do something
          return;
        }
        throw; // "rethrow" exception
      }
    }

    private void Test2() {
      throw new Exception("Test");
    }

Calling "DoTest()" with Microsoft .NET (on Windows) results basically in this stacktrace:

  System.Exception: Test
     at Program.Test2()
     at Program.Test1()
     at Program.DoTest()

While in MonoDroid it results in this stacktrace:

  System.Exception: Test
     at Program.Test1()

Note how the stackframes "DoTest()" and "Test2()" are missing.

I'm running MfA 4.2.6, Android 4.1.
Comment 1 Sebastian Krysmanski 2012-10-01 09:44:31 UTC
It's actually a Mono bug (not limited to MonoDroid).
Comment 2 Alexander Kyte 2015-04-02 19:02:19 UTC
I can confirm this bug.
Comment 3 Alexander Kyte 2015-04-06 13:31:22 UTC
Some of the problem was related to fixes which appeared in a current PR. We were also truncating the stacktrace at the point which it was caught. I've fixed that in the most recent commit to that branch here: 

https://github.com/mono/mono/pull/1668