0

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

Yogi
  • 9,174
  • 2
  • 46
  • 61
  • What exactly is `Exception` type in your `catch` clause? – zerkms Nov 04 '16 at 04:23
  • Can you share the code of this function's call and the data with which it's called – Samvel Petrosov Nov 04 '16 at 04:25
  • Your code is working in my VS 2015 Community http://take.ms/B7cVc – Samvel Petrosov Nov 04 '16 at 04:32
  • And you haven't told VS to break on all exceptions? – Sami Kuhmonen Nov 04 '16 at 04:35
  • The Exception is the base Exception type. And yes, its working in all my other apps as well - its just this one single annoying app its not working on, and I can't for the life of me figure out why... and I have so much code in here that its not simple to create a new app for this. The input variable at the time of this call is a empty string. Which should just trigger the catch and return null... in short, it should not be breaking here at all, but it is.... and its incredibly annoying lol. – Jason Neering Nov 04 '16 at 04:35
  • No, break on all is turned off. And other apps even in the same solution do not have the issue... its just this one. – Jason Neering Nov 04 '16 at 04:36

2 Answers2

3

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

Community
  • 1
  • 1
0

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.

Scott Chamberlain
  • 124,994
  • 33
  • 282
  • 431