How to make visual studio break only on unhandled exceptions?

19,413

Solution 1

Make sure you have Just My Code Enabled by going into Tools-->Options-->Debugger-->General--> Enable Just My Code. This will change your Debug--> Exceptions Dialog Box to show a CheckBox for User-unhandled Errors.

enter image description here

Solution 2

I cannot find the dialogue in the accepted answer.

In my experience, in Exception Settings, if you hit "Restore the list to default settings", it will not break on exceptions you handled. If you checked a particular exception in Exception Settings, then it will break regardless of whether you handles this exception in your code or not.

Solution 3

For a more updated answer:

When you go to the exception settings right click on the exception type you want, which for C# would probably be Common Language Runtime Exceptions, and enable the "Continue When Unhandled in User Code" setting.

For me this seemed to not break on exceptions that were handled in a try catch or otherwise, but it did break when an unhandled exception occurred. The naming of the option makes it feel a bit iffy but it seems to work exactly as you and I hoped now.

Exception settings
Enable the required setting

Share:
19,413
Brandon Moore
Author by

Brandon Moore

I thought I was wrong once, but I was mistaken.

Updated on June 16, 2022

Comments

  • Brandon Moore
    Brandon Moore almost 2 years

    On my other machines, Visual Studio always broke on errors when there was not a try/catch to handle them, but if there was a try/catch then it didn't break.

    For some reason, on this laptop, it doesn't work that way. It didn't break at all at first, but then I found out how to set it to break by going to debug/exceptions. However, configuring it to break there causes it to always break on exceptions even if there is a try/catch block.

    How do I make it work like I'm used to?

  • Mark Hall
    Mark Hall almost 12 years
    @BrandonMoore no problem, they kind of went out of the way to hide it.
  • Brandon Moore
    Brandon Moore almost 12 years
    And misleading... I'm guessing that most likely I saw that at some point and was like "What? No I want to 'limit' it to just my code".
  • jeromej
    jeromej over 5 years
    Debug > Options is a better option since searching for debug in Tools > Options does show the right window but only with entries containing the word "debug" unless you clear your search.
  • jeromej
    jeromej over 5 years
    Answer is outdated. :(
  • Daniel-Dane
    Daniel-Dane over 2 years
    Remember to enable Just My Code.
  • Shameer
    Shameer over 2 years
    "right click on the exception type you want, which for C# would probably be Common Language Runtime Exceptions, and enable the "Continue When Unhandled in User Code" setting." I can't find this setting...