I am surprised to find out that only very few people are aware of this powerful feature, even though it was available from old vb6 days. Microsoft should do something to popularize this. In Visual Studio, you can set to break the execution the moment exception happens, in the exact line where exception happened. Nice, no? Here are the steps.
- In Visual Studio, when a project is open, click on Debug menu, click on Exceptions. (or press Ctrl+Alt+E)
- Check the check box below Thrown column, against Common Language Runtime Exceptions.
- Run the code again, and watch the code is crashing at line where the error occurred.
- Once the code is crashed, if you want to find out how it is handled by exception handler, press F11 (Step Into).
You can even expand Common Language Runtime Exceptions, and configure for individual exceptions. But I don’t think anyone is going to use this.
You can set this option any time, even in the middle of debugging. There is no need to stop debug and restart.
Remember, this option has importance only when debugging. Don't worry that setting this option will cause your program to crash at production.
I am sure once you find this feature, it becomes a cannot-live-without stuff.
Happy new year.