[Mono-dev] Confusion with throw; and throw e

Konrad Kruczyński konrad.kruczynski at gmail.com
Fri Apr 6 09:39:01 UTC 2012


Hello all,
consider this simple C# program:

using System;

namespace ETest
{
	class MainClass
	{
		public static void Main(string[] args)
		{
			try
			{
				Fun();
			}
			catch(Exception e)
			{
				throw;
			}
		}
		
		public static void Fun()
		{
			throw new Exception("Test");
		}
	}
}


Here's the stack trace:
System.Exception: Test
  at ETest.MainClass.Fun () [0x00000] in Main.cs:21
  at ETest.MainClass.Main (System.String[] args) [0x00000] in Main.cs:11

And another simple program:

using System;

namespace ETest
{
	class MainClass
	{
		public static void Main(string[] args)
		{
			try
			{
				Fun();
			}
			catch(Exception e)
			{
				throw e;
			}
		}
		
		public static void Fun()
		{
			throw new Exception("Test");
		}
	}
}


and the stack trace is exactly the same. Shouldn't the second program's
exception originate from the Main.cs:15, i.e. throw e line? The
generated IL looks good.

--
Regards,
 Konrad



More information about the Mono-devel-list mailing list