[英]How can I prevent the debugger from entering my method when Exception is thrown?
How can I prevent the debugger from entering my method when an exception is thrown, instead show the exception at the method's call site? 如何在抛出异常时阻止调试器输入我的方法,而是在方法的调用站点上显示异常?
For example, if one's code causes an exception to be thrown from mscorlib, the debugger (obviously) does not take them into the non-user code to show the exception's source, only shows the exception at the call site. 例如,如果一个代码导致从mscorlib抛出异常,则调试器(显然)不会将它们带入非用户代码以显示异常的源,只显示调用站点的异常。
In other words, this the default behavior: 换句话说,这是默认行为:
and this is my desired behavior: 这是我想要的行为:
I have tried adding [DebuggerNonUserCode]
and [DebuggerStepThrough]
attributes to my Fail()
method, but no luck. 我尝试将[DebuggerNonUserCode]
和[DebuggerStepThrough]
属性添加到我的Fail()
方法中,但没有运气。
You need to decorate your method with DebuggerHiddenAttribute : 您需要使用DebuggerHiddenAttribute修饰您的方法:
[DebuggerHidden]
public static void Fail() {
throw new Exception("Fail");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.