Jason Neering
Jason Neering

Reputation: 21

Visual Studio breaking when it should not be... Anyone know why?

A little background. I write many data conversion apps for various platforms, and am no novice to using breakpoints, exception handling etc.

I have a range of conversion type methods that will take an object input (usually used directly out of a sqldatareader) and convert it to a specific type output, with a default returned if unable to do a direct conversion. Here is an example:

    public int? GetNullInt(object obj)
    {
        try
        {
            int blah = Convert.ToInt32(obj);
            if (blah == 0)
                return null;
            else
                return blah;
        }
        catch (Exception ex)
        {
            return null;
        }
    }

In this case I want to return null if the object is either not an int or is 0.

Now.. the problem is that even tho this code is wrapped in a try/catch, for some reason in this one single application (windows forms, C#, .NET 4.5.2), Visual Studio is breaking when the input string is not in an expected format. The break asks me if I want to break on this type of exception (check box unchecked), but no matter what settings I set, it keeps breaking, even though I am catching the exception (can set a breakpoint in the catch and "continue" to it, so I know the try/catch is functioning). I have "Reset to default" the exception settings in VS, still no joy.

Now I know I can change this method slightly to use int.TryParse (and I am going to do that now), but that does not solve the underlying problem of why VS is breaking in the first place, since this was NOT an unhandled exception.

Any ideas?

(here is a screenshot of the break)

enter image description here

Photo of the break happening at runtime

Upvotes: 0

Views: 70

Answers (2)

Scott Chamberlain
Scott Chamberlain

Reputation: 127543

From the look of your screenshot you do not have "Just My Code" enabled in the debugger settings

enter image description here

If that setting is not enabled you can't use the "Only catch unhandled exceptions" feature of visual studio.

Upvotes: 0

Munavvar Shaikh
Munavvar Shaikh

Reputation: 109

In visual studio you have new window called Exception settings. This window appears after pressing Ctrl + Alt + E.

In this window you can set the Exception handling.

You code is working fine in my Visual Studio Desktop For Express 2015.

You just need to uncheck all the things in this window. Please refer an Image.

enter image description here

You can refer below post, this is exactly same which you want.

Visual Studio 2015 break on unhandled exceptions not working

Upvotes: 3

Related Questions