C
C#•10mo ago
Simon

Visual Studio Exception Settings

Visual Studio breaks on handled exceptions. I've looked at more than like 20 stackoverflow questions but none of them really helped.
try {
// Do something that throws an exception.
} catch (Exception ex) { }
try {
// Do something that throws an exception.
} catch (Exception ex) { }
VS will stop on a simple code like that. As for my settings, I have Just My Code option enabled. Some people on SO suggested that we should go to Exception Settings menu and enable Continue when unhandled in user code but this makes no sense, I want it to break on unhandled code but continue as it should on handled code. I'm really not sure why this simple feature is so hard to get it working, so I'd really appreciate any help.
8 Replies
mtreit
mtreit•10mo ago
You need to uncheck the exception type in Exception Settings
mtreit
mtreit•10mo ago
No description
mtreit
mtreit•10mo ago
If you uncheck all CLR exceptions it won't break on first chance. Only on second chance (i.e., unhandled.)
mtreit
mtreit•10mo ago
So for instance this only breaks on the second call
No description
Simon
SimonOP•10mo ago
thats the problem, if I just uncheck them it wont break on unhandled exceptions, im not sure why
mtreit
mtreit•10mo ago
Does this trivial test program break for you or not?
using System;

Test("foo");

try
{
Test(null);
}
catch
{
}

Test(null);

static void Test(string something)
{
_ = something ?? throw new ArgumentNullException(nameof(something));
}
using System;

Test("foo");

try
{
Test(null);
}
catch
{
}

Test(null);

static void Test(string something)
{
_ = something ?? throw new ArgumentNullException(nameof(something));
}
You should see the 'Exception Unhandled' box as in my screenshot. In your case there might be an exception handler higher up the stack that is catching it. A true unhandled exception crashes the program. So you should definitely see that dialog.
Simon
SimonOP•10mo ago
yeah youre right i think i have some kind of global handler that just catches all exceptions, i its a big project that i havent touched in years, ill have to take a look at that okay yeah it seems like its a handler from a library that i use which redirects everything somewhere else. i feel dumb for not considering that thank you very much 😅
abdulrauf6514
abdulrauf6514•10mo ago
how to upgrade visual studio 2017 to 2022 i have 2022 in my other laptop but in this machine i have windows 10 and vs 2017 version
Want results from more Discord servers?
Add your server