Reputation: 501
I am debugging exceptions in my code, and I my debugger is set to break when one comes out.
I would like my debugging session to exception-break on a certain part of my code and not another, do you know il there is an argument (or other) I could write in my code to tell the debugger to don't exception-break on this part of code?
The exceptions I debug are API'exceptions with the same type, I can't filter them by type.
Thx
ps: please be advised that I know "Debug / Exception" but this is useless in my case as I don't want to filtrer a certain type of exception, only filter them in a part of the code.
Example:
#region don't want to break at exception
Try
{
//I don't want the debugger to break here
ApiMethodThatThrowException();
}
Catch(Exception){}
#endregion
#region want to break at exception
Try
{
//I want the debugger to break here
ApiMethodThatThrowException();
}
Catch(Exception){}
#endregion
Upvotes: 1
Views: 1001
Reputation: 4002
In addition to @abelenky's answer, I'd like to note that there are certain Exceptions
that Visual Studio won't let you disable (C++ Exceptions
, GPU Memory Access Exceptions
, etc). You then have to look at using the System.Diagnostics
attributes to bypass these Exceptions
in the debugger.
DebuggerHiddenAttribute and DebuggerStepThroughAttribute are two of the attributes that can be used to tell the debugger to skip certains sections of code.
public string ConnectionString{
[DebuggerStepThroughAttribute()]
get {
// Implementation here;
}
}
Above example taken from: Using Attributes to Improve the Quality..
[DebuggerHiddenAttribute]
static void Main(string[] args) {
// Implementation here;
}
Upvotes: 3
Reputation: 64672
In the Visual Studio Menus, go to:
Debug / Exceptions...
In that dialog, you can select when the Debugger should break for each kind of exception.
You can select if it should break when the exception is first thrown, or when it goes unhandled.
You can also add new kinds of exceptions to break (or not break) on.
Here is an article with more details
Upvotes: 1
Reputation: 257
From where the error is going, make sure to use the try
and catch
operators.
Where-ever your broken code is, you can simply do the following:
try {
// Code here
} catch(Exception e) {
}
This will prevent Visual Studio from popping out the error in the middle of the process.
Upvotes: 0