【发布时间】:2012-03-24 12:57:54
【问题描述】:
我编写了以下测试代码,尽管我很确定会发生什么:
static void Main(string[] args)
{
Console.WriteLine(Test().ToString());
Console.ReadKey(false);
}
static bool Test()
{
try
{
try
{
return true;
}
finally
{
throw new Exception();
}
}
catch (Exception)
{
return false;
}
}
果然,程序向控制台写入了“False”。我的问题是,最初返回的 true 会发生什么?有没有办法获取这个值,如果可能的话在 catch 块中,或者如果没有的话,在原始的 finally 块中?
澄清一下,这仅用于教育目的。我永远不会在实际程序中制作如此复杂的异常系统。
【问题讨论】: