Basically I've heard that certain conditions will cause .net to blow past the finally block. Does anyone know what those conditions are?
The only reason a finally block won't get executed is if the thread is terminated abnormally (other than a corrupted stack--but the MDAs should catch that).
The finally block always executes when the try block exits. This ensures that the finally block is executed even if an unexpected exception occurs.
A finally block always executes, regardless of whether an exception is thrown.
exit() will prevent a finally block from executing.
Two possibilities:
The finally block will not be executed when there's a StackOverflowException
since there's no room on the stack to even execute any more code. It will also not be called when there's an ExecutionEngineException
, which may arise from a call to Environment.FailFast()
.
Unless the CLR blows up and goes down with an ExecutingEngineException (I've seen a few in the .net 1.1 days with just the right amount of COM Interop :) .. I think finally should always execute.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With