How to stop execution for ALL exceptions during debugging in Visual Studio?

In my code, I currently have an exception handling setting that logs exceptions in text files. However, when I debug the code, I would prefer not to handle the exceptions and let it stop, rather than reading the file, setting a breakpoint, etc. Is there an easy way to do this using build and release configurations (something like a preprocessor directive that I could use to comment on some kind of exception handling code)?

It turns out that there is a better solution than the original question asked, see the first answer.

+3
source share
5 answers

C # does has preprocessor directives (e.g. if, define, etc.) that you could use for this purpose.

However, you can also change the settings in the "Debugging → Exceptions ..." section in Visual Studio so that the debugger crashes every time an exception is thrown (before execution passes to the catch block).

+7
source

Try something like this:

if ( System.Diagnostics.Debugger.IsAttached )
    System.Diagnostics.Debugger.Break();
else 
    LogException(); 
+4
source
#if DEBUG
// Something
#else
// Something else
#endif
+1

I hesitate to use preprocessor directives. I would suggest that you want something that is easily applicable to your entire solution, and also not stick to preprocessor directives throughout your code.

From previous answers, Joel is good. However, you can do the same by going to "Debug / Exceptions" and make sure that the checkboxes in the line "Source language exceptions" are selected. By default, the user is raw.

0
source

Source: https://habr.com/ru/post/1709530/


All Articles