禁止第一次机会异常 [英] Suppress first chance exceptions

查看:235
本文介绍了禁止第一次机会异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能打压特定代码行在Visual Studio中第一次有机会supressions(C#调试器)?

Is it possible to suppress first chance supressions in Visual Studio (C# debugger) for specific lines of code?

我想用第一次机会异常在调试器,但也有大约50第一次机会异常,我需要去通过每一个调试会话之前,我对有趣的代码。

I want to use first chance exceptions in the debugger, but there are about 50 first chance exceptions I need to go through every debug session before I get to the interesting code.

目前,我手动关闭第一次机会异常,然后打开它们,但这是一个麻烦和时间下沉。

Currently, I turn off first chance exceptions and then manually turn them on, but that's a hassle and a time sink.

推荐答案

由于.NET 2.0,如果您标记的的 [ DebuggerNonUserCode ] 属性,调试器将跳过它第一次机会异常。

DebuggerNonUserCodeAttribute Class

As of .NET 2.0, if you mark an method with the [DebuggerNonUserCode] attribute, the debugger will skip first chance exceptions in it.

从MSDN报价链接(着重是我的):

Quote from MSDN link (emphasis added is mine):

会员
是不是由专门创建的代码
的一部分用户的可以
复杂的调试经验
的。
此属性可以禁止这些辅助类型和成员在
调试器窗口的显示
,并自动通过

步骤,而不是进入,
设计师提供的代码。

members that are not part of the code specifically created by the user can complicate the debugging experience. This attribute suppresses the display of these adjunct types and members in the debugger window and automatically steps through, rather than into, designer provided code.

有没有运行时的行为除了调试,与此属性关联。

There is no runtime behaviour apart from debugging, associated with this attribute.

不过,如果你只有一个方法,一定行拟列入Visual Studio的第一个机会异常处理机制等多条线路被排除,有可能不是一个解决方案此粒度级别。您可以随时重构的大型方法分成多个方法和使用属性上选择的。

However if you have just one method with certain lines intended for inclusion in Visual Studio's first chance exception handling mechanism, and other lines to be excluded, there's likely not a solution at this level of granularity. You can always refactor a large method into multiple methods and use the attribute on select ones.

其他信息...

例如,从这篇文章

using System.Diagnostics;
using XL = Microsoft.Office.Interop.Excel;

public static class WorkbookExtensions
{
    [DebuggerNonUserCode]
    public static bool TryGetWorksheet(this XL.Workbook wb, string worksheetName, out XL.Worksheet retrievedWorksheet)
    {
        bool exists = false;
        retrievedWorksheet = null;

        try
        {
            retrievedWorksheet = GetWorksheet(wb, worksheetName);
            exists = retrievedWorksheet != null;
        }
        catch(COMException)
        {
            exists = false;
        }

        return exists;
    }

    [DebuggerNonUserCode]
    public static XL.Worksheet GetWorksheet(this XL.Workbook wb, string worksheetName)
    {
        return wb.Worksheets.get_Item(worksheetName) as XL.Worksheet;
    }
}

The文章显示VS可能是有用的项目选择相关结果

The article shows related VS project options that might be useful.

这篇关于禁止第一次机会异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆