try {
// Do stuff
}
catch (Exception e) {
throw;
}
finally {
// Clean up
}
In the above block when is the finally block called? Before the
Why not try it:
outer try
inner try
inner catch
inner finally
outer catch
outer finally
with code (formatted for vertical space):
static void Main() {
try {
Console.WriteLine("outer try");
DoIt();
} catch {
Console.WriteLine("outer catch");
// swallow
} finally {
Console.WriteLine("outer finally");
}
}
static void DoIt() {
try {
Console.WriteLine("inner try");
int i = 0;
Console.WriteLine(12 / i); // oops
} catch (Exception e) {
Console.WriteLine("inner catch");
throw e; // or "throw", or "throw anything"
} finally {
Console.WriteLine("inner finally");
}
}