I know I can prevent the Visual Studio debugger from stopping on certain kind of exceptions when they're thrown (via the Ctrl-Alt-E "Exceptions" dialog). But what if want to control this from code, for some specific places rather than on the all-or-none basis? For example:
try
{
SomeMethod(token);
}
catch (OperationCancelledException)
{
return false;
}
// ...
void SomeMethod(CancellationToken token)
{
// ...
// I don't want the debugger to stop on the following line
#pragma ignore(OperationCancelledException, true)
token.ThrowIfCancellationRequested();
#pragma ignore(OperationCancelledException, false)
}
I use the hypothetic #pragma ignore
to illustrate what I mean, but does something like this actually exist?
UPDATE to address "Unclear what you're asking" closure vote. Try this code in the debugger: https://dotnetfiddle.net/npMk6r. Make sure all exceptions are enabled in the Ctrl-Alt-E dialog. The debugger will be stopping on the throw new OperationCanceledException("cancelled1")
line upon each iteration of the loop. I don't want that to happen as it's annoying. Yet, I do want it to stop on the last throw outside the loop, throw new OperationCanceledException("cancelled2")
(or anywhere else, for that matter).
you try the following way:
When "Just My Code" is enabled, Visual Studio in some cases will break on the line that throws the exception and display an error message that says "exception not handled by user code." This error is benign. You can press F5 to continue from it, and see the exception-handling behavior that is demonstrated in the examples below. To prevent Visual Studio from breaking on the first error, just uncheck the "Just My Code" checkbox under Tools, Options, Debugging, General.
from here
hope this helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With