Identical to "How do exceptions work (behind the scenes) in C++", but for C#.
I know that the steps below have to be performed when an exception is thrown.
- Find the nearest handler for the exception type;
- Unwind the stack up to the handler level;
- Call the handler;
- Find and call every
finally
blocks.
How does .NET handles these operations? How does the mapping for the "current" handlers work? How much code is emitted in a try/catch block? And in a throw block?