Debugging and monitoring exceptions
Debugging exceptions is a bit different compared to debugging normal code because the natural flow gets interrupted and handled by the runtime. Unless you put a breakpoint on the code that handles the exception, there is a risk of not understanding where exactly the problem started. This can happen when an exception is caught and not re-thrown or if the method does not re-throw within the catch
block.
This may seem like an important downside of the exception model, but the .NET runtime provides all the necessary support to overcome this issue. In fact, the runtime has built-in support for the debuggers, providing valuable hooks to the debugger willing to intercept the exceptions.
From a debugger perspective, you have two possibilities, or chances, to intercept any exception being thrown:
- First-chance exceptions represent the exceptions at a very early stage, as soon as they are thrown and before jumping to their handlers, if any. The...