Don't break on handled exceptions

Greg Reese 26 Reputation points
2021-02-09T20:47:51.627+00:00

How do I make Visual Studio 2019 NOT break on all user-handled exceptions? I'm working in C++ if that matters.

Developer technologies | Visual Studio | Debugging
0 comments No comments
{count} votes

Accepted answer
  1. Dylan Zhu-MSFT 6,426 Reputation points
    2021-02-10T07:02:24.493+00:00

    Hi GregReese-5829,

    You could try to add your exception into C++ Exceptions, then keep it unchecked.
    66198-image.png

    Since I try to create a simple handled exception, it can work as normal. If the above method doesn't work on your side, could you provide a sample which can help us reproduce it?
    66150-image.png

    Best Regards,
    Dylan


    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our **documentation to enable e-mail notifications if you want to receive the related email notification for this thread.**

    0 comments No comments

3 additional answers

Sort by: Most helpful
  1. Michael Taylor 60,161 Reputation points
    2021-02-09T21:02:05.86+00:00

    In most cases the debugger should only break if an exception isn't handled. But there are special cases. One case would be an exception that crosses a process boundary. Another is for certain exceptions that are going to crash the program. In some cases the debugger options can be changed but an unhandleable exception is going to break in the debugger even if handled (e.g. stack overflow).

    Go to the Exception Settings window. Inside this window is a list of all the exceptions that can be thrown. You can pick and choose how to handle the exceptions. For CLR exceptions you have more control. For C++ exceptions you can edit the condition to break into the debugger when certain exceptions are thrown, irrelevant if they are handled or not. In your case, to prevent VS from breaking when thrown ensure the box is unchecked and it shouldn't break when thrown. Win32 exceptions have their own category and work the same way.

    0 comments No comments

  2. Greg Reese 26 Reputation points
    2021-02-09T22:58:54.157+00:00

    Hi @Michael Taylor ,

    In most cases the debugger should only break if an exception isn't handled.

    That's what I would think but it doesn't appear to be so.

    Go to the Exception Settings window. Inside this window is a list of all the exceptions that can be thrown. You can pick and choose how to handle the exceptions.

    I don't think this helps. The only condition you can set is whether or not an exception comes from a certain module. I want the debugger to not break on any exception that my code handles and to break on any exception that my code does not handle, regardless of where the exception comes from.

    In your case, to prevent VS from breaking when thrown ensure the box is unchecked and it shouldn't break when thrown. Win32 exceptions have their own category and work the same way.

    I tested this by clearing all of the boxes under C++ Exceptions, Common Language Runtime Exceptions and Win32 Exceptions but the debugger still stopped on the exceptions that I handled.

    I searched the Web and this problem appears to have started after VS 2015, which did allow the debugger to ignore handled exceptions. I haven't seen a solution yet but many of the suggestions said to ensure that under Tools|Options|Debugging|General, the box Enable Just My Code is checked. I have it set that way but it still doesn't work.

    Greg


  3. Greg Reese 26 Reputation points
    2021-02-11T19:55:47.59+00:00

    I wrote some simple try-catch blocks, like the one @Dylan Zhu-MSFT suggested, and they did work. So after looking into this more I figured it out. What I was throwing was an exception class that I wrote. The constructor for that class would sometimes fail, i.e. throw an exception, and that's why the thrown object never made it to the catch block. In other words

    try  
    {  
       throw My_Exception();  
    }  
    catch( ... )  
    {  
       // never makes it here if My_Exception() constructor throws  
    }  
    

    So basically - my bad.

    Thanks everyone for your suggestions though.

    Greg Reese

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.