了解罚球前和抛之间的区别保留原来的堆栈跟踪/ LineNumbers,为什么原来的堆栈跟踪保存在这个例子中:在.NET异常
static void Main(string[] args)
{
try
{
LongFaultyMethod();
}
catch (System.Exception ex)
{
Console.WriteLine(ex.StackTrace);
}
}
static void LongFaultyMethod()
{
try
{
int x = 20;
SomethingThatThrowsException(x);
}
catch (Exception)
{
throw;
}
}
static void SomethingThatThrowsException(int x)
{
int y = x/(x - x);
}
但不是在这一个:
static void Main(string[] args)
{
try
{
LongFaultyMethod();
}
catch (System.Exception ex)
{
Console.WriteLine(ex.StackTrace);
}
}
static void LongFaultyMethod()
{
try
{
int x = 20;
int y = x/(x - 20);
}
catch (Exception)
{
throw;
}
}
第二种情况是产生与相同的输出,那么会出现会出现什么情况?
在这两种情况下,都希望看到y被初始化的行号。
这很好,谢谢你的信息。 – Nariman 2010-04-05 14:37:46