tgandrews tgandrews - 17 days ago 4x
C# Question

When is finally run if you throw an exception from the catch block?

try {
// Do stuff
catch (Exception e) {
finally {
// Clean up

In the above block when is the finally block called? Before the throwing of e or is finally called and then catch?


It would be called after e is re-thrown (i.e. after the catch block is executed)

editing this 7 years later - one important note is that if e is not caught by a try/catch block further up the call stack or handled by a global exception handler, then the finally block may never execute at all.