[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)
commitf985c6809b976935c0c5031042bb76339cbe5a72
treebd3dc09247c0955e124a1c699a0f686b80020b52
parent24a328b83cbaa4452ba41035482a32868aacd5cf
[runtime] Overwrite stacktrace for exception on re-throw. Fixes #1856.

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.
mono/mini/exceptions-amd64.c
mono/mini/exceptions-arm.c
mono/mini/exceptions-ia64.c
mono/mini/exceptions-mips.c
mono/mini/exceptions-ppc.c
mono/mini/exceptions-s390x.c
mono/mini/exceptions-sparc.c
mono/mini/exceptions-x86.c
mono/tests/Makefile.am
mono/tests/exception18.cs [new file with mode: 0644]