选择性地忽略C#代码中引发的异常 [英] Selectively ignore thrown exceptions in C# code
问题描述
我需要编辑打破我的代码中的这个异常,而不是在同一个函数中。
如果我正确理解,尝试做的是调试一些NullReferenceException,但是要在调试时暂时忽略其他人,您可以通过标记要使调试器忽略的功能来执行此操作,使用DebuggerNonUserCode 属性。
[DebuggerNonUserCode]
private void MyMethod()
{
// NullReferenceException异常捕获此方法将
//不会导致Debugger在此停止..
}
注意所谓的方法。这只是说,如果调试器设置为始终在 NullReferenceException
异常中断,调试器不会导致调试器中断。而且这只适用于方法,而不是方法中的任意代码段。
I have a function in C# code where a NullReferenceException is thrown periodically (expected behavior), but caught. Is there a way I can tell the Visual Studio debugger to not break on this exception for this particular section of my code?
EDIT I need to break on this exception elsewhere in my code, but not in the same function.
If I understand correctly and what you're trying to do is debug some NullReferenceException(s) but want to temporarily ignore others while debugging, you might be able to do this by marking functions that you want the debugger to ignore with the DebuggerNonUserCode attribute.
[DebuggerNonUserCode]
private void MyMethod()
{
// NullReferenceException exceptions caught in this method will
// not cause the Debugger to stop here..
}
NOTE that this will only work if the exceptions are caught in said methods. It's just that they won't cause the debugger to break if you have the debugger set to always break on NullReferenceException
exceptions. And that this only works on methods, and not arbitrary sections of code inside of a method..
这篇关于选择性地忽略C#代码中引发的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!