我回顾了一些code的朋友说,他使用的是内部return语句的try-finally块。请问code在最后一节仍然火即使在try块其余不?
例如:
公共BOOL的someMethod()
{
尝试
{
返回true;
抛出新的异常(测试); //似乎并没有得到执行
}
最后
{
// code问题
}
}
解决方案
简单的回答:是的,
I'm reviewing some code for a friend and say that he was using a return statement inside of a try-finally block. Does the code in the Finally section still fire even though the rest of the try block doesn't?
Example:
public bool someMethod()
{
try
{
return true;
throw new Exception("test"); // doesn't seem to get executed
}
finally
{
//code in question
}
}
解决方案
Simple answer: Yes.
上一篇:要求Windows Vista的UAC提升,如果路径保护?路径、Windows、Vista、UAC
下一篇:是String.Contains()比String.IndexOf快()?String、Contains、IndexOf