Another interview question which was expecting a true / false answer and I wasn't too sure.
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Generic Generics in Managed C++
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
Straight from MSDN:
http://msdn.microsoft.com/en-us/library/zwc8s4fz(VS.71,loband).aspx
Finally block is guaranteed to be executed in any case.
Finally will happen everytime for that try catch block
Finally is always executed. I not depends on how the try block works. If u have to do some extra work for both try and cath, it is better to put in finally block. So you can gurantee that it is always executed.
Generally the finally block is always executed regardless of whether an exception is thrown or not and whether any exception is handled or not.
There are a couple of exceptions (see other answers for more details).
finally
is executed most of the time. It's almost all cases. For instance, if an async exception (likeStackOverflowException
,OutOfMemoryException
,ThreadAbortException
) is thrown on the thread,finally
execution is not guaranteed. This is why constrained execution regions exist for writing highly reliable code.For interview purposes, I expect the answer to this question to be false (I won't guarantee anything! The interviewer might not know this herself!).