valentin tihomirov said:
I'm sure it is pretty obvious. But if you like
using System; // line 1
class Rerise {
public static void Main(string[] args) {
try {
throw new Exception("Can I escape?"); // line 8
} catch (Exception e) {
Console.WriteLine("Logged error: " + e.Message);
throw e; // line 11
}
}
}
Compile it with /debug key and see that stack trace will point to 'line
11' where it is rethrown rather than to 'line 8' where it originates.
It doesn't build a new stacktrace, it only changes the line reported for the
method where ther throw; occurs.
You can chack it with following programm:
<code>
using System;
class A
{
static void Main()
{
try
{
ThrowException(); //line 9
}
catch (Exception e)
{
throw; //line 13
}
}
static void ThrowException()
{
throw new Exception(); //line 19
}
}
</code>
stacktrace looks like:
A.ThrowException() .... line 19
A.Main ... line 13
If you change catch(Exception e) to catch (SystemException e), wich prevents
the exception from being caught, the trck trace looks like following:
A.ThrowException() ... line 19
A.Main ... line 9
So, the methods in the stacktrace remain the same, but the line reported is
changed.
Christof