[runtime] Overwrite stacktrace for exception on re-throw. Fixes #1856.
authorAlexander Kyte <alexmkyte@gmail.com>
Mon, 30 Mar 2015 17:23:59 +0000 (13:23 -0400)
committerAlexander Kyte <alexander.kyte@xamarin.com>
Mon, 6 Apr 2015 17:24:47 +0000 (13:24 -0400)
This fixes a bug where we did not completely mimic .NET's exception handling.

We previously held onto the stacktrace when an exception was thrown if it already had one. This differs from how .NET behaves, which is to always set the stacktrace to the place that it was last thrown.

Ex:

using System;

class C
{
    static Exception e;

    static void Throw ()
    {
        try {
            int.Parse (null);
        } catch (Exception ex) {
            e = ex;
        }
    }

    public static void Main ()
    {
        Throw ();

        try {
            throw e;
        } catch (Exception ex) {
            Console.WriteLine (ex.StackTrace);
        }
    }
}

Would previously output:

  at System.Int32.Parse (System.String s) [0x00000] in <filename unknown>:0
  at C.Throw () [0x00000] in <filename unknown>:0

when

   at C.Main()

is what .NET output. After this commit we output the same stacktrace as .NET.


No differences found