try
{
Console.WriteLine("A");
throw new InvalidOperationException();
}
finally
{
Console.WriteLine("B");
}What is printed before the exception propagates out of this code block (assuming nothing catches it further up)?
- aB then A
- bA then B✓
- cOnly A (finally is skipped since no catch)
- dOnly B (A is buffered and lost since exception was thrown)
Explanation:The try block runs first, printing "A", then throws. Before the exception can propagate further up the call stack, the finally block always runs, printing "B". Only after that does the exception continue propagating.