开发者

Make Visual Studio ignore exceptions?

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 sig开发者_StackOverflow社区nal a validation error.) Is there a way to mark that one exception as ignored?

I'm following this tutorial.


Debug -> Exceptions -> Uncheck


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.


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

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.

// [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;
    }
}


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.


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


Putting this above the property that throws the exception seems like it should work but apparently doesn't: [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.");
            }
        }
    }


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

Debug > Windows > Exception Settings

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜