简体   繁体   English

如何在抛出异常时阻止调试器进入我的方法?

[英]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.

相关问题 如何从代码中更改“引发异常时中断”调试器行为 - How can I change “Break When an Exception is Thrown” debugger behaviour from code 如何防止在我运行 WPF MVVM 应用程序时引发“System.StackOverFlowException”异常? - How to prevent the "System.StackOverFlowException" exception being thrown when i run my WPF MVVM application? 如何使用附加的调试器运行测试时,如何防止VerificationException? - How can I prevent a VerificationException when running a test with attached debugger? 在反序列化具有来自 JSON 的重复键的字典时,如何强制抛出异常? - How can I force an exception to be thrown when deserializing a dictionary with duplicated keys from JSON? 如何从CompletedEventArgs中获取抛出的异常类型? - How can I get the type of thrown exception from CompletedEventArgs? 防止从 BeginInvoke 抛出时丢弃外部异常 - Prevent outer exception from being discarded when thrown from BeginInvoke 抛出未处理的异常时阻止 Microsoft 日志记录 - Prevent Microsoft Logging from log when Unhandled exception thrown 我如何知道是否故意抛出了异常? - How can i tell if an Exception was deliberately thrown? 如何防止Visual Studio中断SignalR集线器中引发的异常? - How to prevent Visual Studio from breaking on exception thrown in SignalR hub? 在UWP应用(Windows 10)中,如何防止Windows操作系统进入睡眠模式? - In UWP app (Windows 10), how can I prevent Windows OS from entering Sleep mode?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM