Skip to content

linenum of CallStack will change after rethrow an Exception?  #6710

@yyjdelete

Description

@yyjdelete
//#define NET_FRAMEWORK

using System;
#if NET_FRAMEWORK
using System.Globalization;
using System.Threading;
#endif

namespace ConsoleApplication1
{
    internal class Program
    {
        private static void Main(string[] args)
        {
#if NET_FRAMEWORK
            Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;
#endif
            try
            {
                try
                {
                    try
                    {
#line 1111
                        DoThrow();
                    }
                    catch (Exception e1)
                    {
#line 2000
                        Console.WriteLine("Orig: " + e1.ToString());
#line 2222
                        throw;
                    }
                }
                catch (Exception e2)
                {
#line 3000
                    Console.WriteLine("ReThrow: " + e2.ToString());
#line 3333
                    throw e2;
                }
            }
            catch (Exception e3)
            {
#line 4000
                Console.WriteLine("Throw: " + e3.ToString());
            }
            Console.ReadLine();
        }

        private static void DoThrow()
        {
#line 4444
            throw new Exception("Test");
        }
    }
}

And Got

Orig: System.Exception: Test
   at ConsoleApplication1.Program.DoThrow() in ***\Program.cs:line 4444
   at ConsoleApplication1.Program.Main(String[] args) in ***\Program.cs:line 1111
ReThrow: System.Exception: Test
   at ConsoleApplication1.Program.DoThrow() in ***\Program.cs:line 4444
   at ConsoleApplication1.Program.Main(String[] args) in ***\Program.cs:line 2222
Throw: System.Exception: Test
   at ConsoleApplication1.Program.Main(String[] args) in ***\Program.cs:line 3333

Notice that the line num of Main is different between Orig and ReThrow, and I don't find any doc for line num(only found that rethrow will keep the original stack trace information with the exception, CA2200: Rethrow to preserve stack details).
Is it work as expected?

Test with both .net framework 4.6.2 and core 1.0.1, and got the same result.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions