12

Suppose I have a function that throws an exception. Suppose this function is called by a third-party DLL, and the third-party DLL will handle the exception I’ve thrown.

If Visual Studio decides that the third-party DLL is not "user code" (as seen in the image below) then it will stop on my exception by default, even though it gets handled later. It isn’t exactly wrong to do so; it clearly explains that the exception was unhandled by user code. But what is it that makes Visual Studio call some DLLs "user code" and others not?

enter image description here

I had a theory that this happens because the symbols aren’t loaded, but there are modules in the list that have loaded symbols but are still not considered "user code".

Roman Starkov
  • 59,298
  • 38
  • 251
  • 324
  • For others the Modules window is found on the Debug menu, choose Windows, and then click Modules. A useful display for tracking down just what .dll is being used (my code wouldn't debug because it was using a copy of the lib in the GAC rather than the output from the referenced project), thanks for pointing it out. – RyanfaeScotland Apr 09 '15 at 13:29

1 Answers1

13

Yes, without a .pdb file the debugger can't tell whether it is user code or not. It is explained reasonably well in the MSDN article:

To distinguish user code from non-user code, Just My Code looks at three things: DBG Files, PDB files, and optimization.

In a standard Debug build, optimization is turned off and debug symbols are created for all modules. When you run a debug build, those modules are considered to be user code. If I call a library function that is optimized and does not have debug symbols, however, it is not user code. Just My Code prevents execution from stopping at breakpoints in the library code, which is usually not code you are interested in debugging. In the Breakpoints window, those breakpoints will appear with the Disabled Breakpoint icon.

Community
  • 1
  • 1
Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • This is perfect. With this in mind, I’ve posted an answer for [preventing the debugger stopping on all exceptions in a library](http://stackoverflow.com/a/9616890/33080) and added [another workaround for NUnit’s `Assert.Throws` halting](http://stackoverflow.com/a/9609494/33080). Nice! – Roman Starkov Mar 08 '12 at 14:40
  • 1
    This is still vague. I reckon it's safe to say "User code = No optimization + debug symbols" ? – ivan_pozdeev Dec 26 '14 at 02:28