瞭解罰球前和拋之間的區別保留原來的堆棧跟蹤/ 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