Make Visual Studio ignore exceptions?

前端 未结 7 2066
一个人的身影
一个人的身影 2021-01-12 02:27

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 th

相关标签:
7条回答
  • 2021-01-12 02:37

    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;
        }
    }
    
    0 讨论(0)
  • 2021-01-12 02:37

    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.");
                }
            }
        }
    
    0 讨论(0)
  • 2021-01-12 02:49

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

    Debug > Windows > Exception Settings

    0 讨论(0)
  • 2021-01-12 02:52

    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.

    0 讨论(0)
  • 2021-01-12 02:56

    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.

    0 讨论(0)
  • 2021-01-12 02:57

    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
    
    0 讨论(0)
提交回复
热议问题