最终会在这种情况下执行(在C#中)?
try
{
// Do something.
}
catch
{
// Rethrow the exception.
throw;
}
finally
{
// Will this part be executed?
}
Run Code Online (Sandbox Code Playgroud)
Fre*_*örk 11
是的,最后总是执行.
演示行为的简单示例:
private void Button_Click(object sender, EventArgs e)
{
try
{
ThrowingMethod();
}
catch
{
}
}
private void ThrowingMethod()
{
try
{
throw new InvalidOperationException("some exception");
}
catch
{
throw;
}
finally
{
MessageBox.Show("finally");
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8946 次 |
| 最近记录: |