Nick Heiner
Nick Heiner

Reputation: 122412

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 signal a validation error.) Is there a way to mark that one exception as ignored?

I'm following this tutorial.

Upvotes: 11

Views: 29288

Answers (7)

plasma
plasma

Reputation: 297

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.

Upvotes: 2

Felix
Felix

Reputation: 4081

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

Debug > Windows > Exception Settings

Upvotes: 0

Mattias
Mattias

Reputation: 89

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

Upvotes: 5

Nick Heiner
Nick Heiner

Reputation: 122412

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.");
            }
        }
    }

Upvotes: 0

Pomoinytskyi
Pomoinytskyi

Reputation: 55

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

Upvotes: 0

user180326
user180326

Reputation:

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.

Upvotes: 5

Jean-Bernard Pellerin
Jean-Bernard Pellerin

Reputation: 12670

Debug -> Exceptions -> Uncheck

Upvotes: 19

Related Questions