visual-studio 让 Visual Studio 忽略异常?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3688574/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 12:26:51  来源:igfitidea点击:

Make Visual Studio ignore exceptions?

c#.netvisual-studiosilverlight

提问by Nick Heiner

I'm using exceptions to validate a control's input in Silverlight 4. When I throw an invalid input exception, VS 2010 displays the popup and stops the program. I ignore this and resume the program, and everything continues fine (since the exception is used to signal a validation error.) Is there a way to mark that one exception as ignored?

我在 Silverlight 4 中使用异常来验证控件的输入。当我抛出无效输入异常时,VS 2010 会显示弹出窗口并停止程序。我忽略它并恢复程序,一切都继续正常(因为异常用于发出验证错误的信号。)有没有办法将该异常标记为忽略?

I'm following this tutorial.

我正在关注本教程

回答by Jean-Bernard Pellerin

Debug -> Exceptions -> Uncheck

调试 -> 异常 -> 取消选中

回答by Nick Heiner

Menu, Debugger, Exceptions...

菜单、调试器、异常...

In that dialog, you can remove the checkmark in the 'thrown' column for one exception, of for a whole namespace. You can add your own. etc.etc.

在该对话框中,您可以为整个命名空间的一个异常删除“thrown”列中的复选标记。您可以添加自己的。等等等等

回答by Mattias

I got [System.Diagnostics.DebuggerHidden()]to work if I also selected

[System.Diagnostics.DebuggerHidden()]如果我也选择了,我就开始工作

Debug > Options > Debugging > General > Enable Just My Code (Managed only).

调试 > 选项 > 调试 > 常规 > 仅启用我的代码(仅限托管)。

I access the Excel object model a lot, and I really like to be able to run the debugger and catching all exceptions, since my code normally is exception less. However, the Excel API throws a lot of exceptions.

我经常访问 Excel 对象模型,我真的很喜欢能够运行调试器并捕获所有异常,因为我的代码通常很少出现异常。但是,Excel API 会引发很多异常。

// [System.Diagnostics.DebuggerNonUserCode()]  works too
[System.Diagnostics.DebuggerHidden()]
private static Excel.Range TrySpecialCells(Excel.Worksheet sheet, Excel.XlCellType cellType)
{
    try
    {
        return sheet.Cells.SpecialCells(cellType);
    }
    catch (TargetInvocationException)
    {
        return null;
    }
    catch (COMException)
    {
        return null;
    }
}

回答by UniSize

When you run Visual Studio in debug mode, there are Exception Setting on the bottom tool bar. Once you click it, there are all type exceptions. Uncheck exceptions that you want. For the Custom exception you made for this project, they are located in Common Language Runtime Exceptions, at very bottom. Hope this helpful.

在调试模式下运行 Visual Studio 时,底部工具栏上有异常设置。单击它后,所有类型都将出现异常。取消选中您想要的异常。对于您为此项目创建的自定义异常,它们位于最底部的公共语言运行时异常中。希望这有帮助。

回答by Pomoinytskyi

You can disable some throw block by surrounding in the block

您可以通过在块中包围来禁用一些抛出块

#if !DEBUG
       throw new Exception();
/// this code will be excepted in the debug mode but will be run in the release 
#endif

回答by Nick Heiner

Putting this above the property that throws the exception seems like it should work but apparently doesn't: [System.Diagnostics.DebuggerHidden()]:

将其放在引发异常的属性上方似乎应该可以工作,但显然没有 [System.Diagnostics.DebuggerHidden()]::

    private String name;

    [System.Diagnostics.DebuggerHidden()]
    public String Name
    {
        get
        {
            return name;
        }
        set
        {
            if (String.IsNullOrWhiteSpace(value))
            {
                throw new ArgumentException("Please enter a name.");
            }
        }
    }

回答by Felix

From Visual Studio 2015 onward there is an Exception Settings window for this.

从 Visual Studio 2015 开始,有一个用于此的异常设置窗口。

Debug > Windows > Exception Settings

调试 > Windows > 异常设置