我的简单例子是:
void FixedUnalterableMethod()
{
try
{
throw new Exception("Exception 1"); //line 12.
}
finally
{
throw new Exception("Exception 2"); //line 16.
}
}
void Method1()
{
try
{
FixedUnalterableMethod(); //line 24.
}
catch (Exception ex)
{
var messageWithStackTrace = ex.ToString(); //line 28.
Console.WriteLine(messageWithStackTrace);
}
}
控制台输出如下:
System.Exception: Exception 2
at Program.FixedUnalterableMethod() in ...\Program.cs:line 16
at Program.Main(String[] args) in ...\Program.cs:line 24
问题是如何得知
Exception 1
已发生?
是否有一种方法可以在我的 StackTrace 中包含 Exception 1
(位于第28行) ?
当然我无法修改 FixedUnalterableMethod()
方法!
finally
中抛出一个异常?这似乎很奇怪,因为你不应该有一个总是失败的方法。 - ProgrammingLlama