【发布时间】:2013-12-16 08:15:39
【问题描述】:
我读到finally 键使try-catch 块最终工作,甚至函数是否抛出异常。但我想知道如果我不将代码放入 finally 块(如下面的 Function_2)中会有什么不同,这是我用来编码的方式。谢谢!
void Function_1()
{
try
{
throw new Exception();
}
catch
{
}
finally //Have finally block
{
Other_Function();
}
}
void Function_2()
{
try
{
throw new Exception();
}
catch
{
}
Other_Function(); //Don't have finally block
}
【问题讨论】:
-
将
throw new Exception()替换为return,您会看到不同之处。
标签: c# .net try-catch-finally