Monday, April 20, 2015

Debugging errors that have already been caught in a Try Catch block.

I was having issues finding errors that were being caught in a Try Catch block and never handled.
Try
  <Code that throws an error>
Catch
End Try
With a large amount of errors being swallowed whole like this, I was having trouble determining where an issue may have developed in the code because of something I changed.  On the surface everything appeared to run fine since no errors bubbled to the surface. However, I wouldn't get the results I was expecting.  This often meant stepping through individual lines of code until I stumbled on the culprit. What I found is that you can force Visual Studio to break on thrown errors even if they are handled in a Try Catch block.

  • Either use "Ctrl-Alt-E" or on the Menu bar -> Debug -> Exceptions...
  • Check the "Thrown" box for the exceptions you want to break on