5

This question seems very similar to previous, but the case is a bit different (perhaps better demonstrating the problem), though goal is the same.

xaml:

<TextBox Text="{local:ExceptionBinding Path=Color1}" />

cs:

public class ExceptionBinding : Binding
{
    public ExceptionBinding()
    {
        ValidationRules.Add(new ExceptionValidationRule());
    }
}

vm:

    Color _color1;
    public string Color1
    {
        get { return (new ColorConverter()).ConvertToString(_color1); }
        set { _color1 = (Color)ColorConverter.ConvertFromString(value); }
    }

When this code runs standalone, for input 123 red border is shown around TextBox (field value is not changing). Entering red or #FF0000 will remove border and update field value.

Problem: when running program under Visual Studio, entering 123 will throw at ConvertFromString (undocumented btw):

An exception of type 'System.FormatException' occurred in PresentationCore.dll but was not handled in user code

Additional information: Token is not valid.

How to prevent Visual Studio from interrupting program execution?

Community
  • 1
  • 1
Sinatr
  • 20,892
  • 15
  • 90
  • 319
  • if you are getting an exception in visual studio, so are your users. if you want to continue to program execution, just hit F5 (or the green arrow play button on VS) to continue to program execution. – user1666620 Feb 23 '16 at 14:22
  • @user1666620, it's not the bug, I'd like to avoid execution being interrupted. – Sinatr Feb 23 '16 at 14:23
  • i've updated my comment as you responded. – user1666620 Feb 23 '16 at 14:24
  • can you just handle the exception so its not a problem? – Jacobr365 Feb 23 '16 at 14:25
  • Possible duplicate of [Make Visual Studio ignore exceptions?](http://stackoverflow.com/questions/3688574/make-visual-studio-ignore-exceptions) – user1666620 Feb 23 '16 at 14:26
  • @Jacobr365, if I handle it, then the whole purpose of validation with `ExceptionValidationRule` is killed (there will be no red border anymore). – Sinatr Feb 23 '16 at 14:28
  • @user1666620, I can't ignore `FormatException` as it can be thrown in other places of the program and I may need to debug those. It's rather uncomfortable to disable/enable it like this. – Sinatr Feb 23 '16 at 14:30
  • In the catch block just paint a red outline. – Jacobr365 Feb 23 '16 at 14:30
  • @Sinatr if you don't want to ignore exceptions, just continue the program execution by hitting F5 to continue the program. – user1666620 Feb 23 '16 at 14:31
  • 1
    @user1666620, once, second time, third time, ... , 100500 time? There are several places where I am currently using `ExceptionValidationRule`, it gets uncomfortable. This is why I am here. – Sinatr Feb 23 '16 at 14:33
  • @Sinatr do i have to become your google searcher? https://www.google.ie/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=visual+studio+ignore+specific+exception http://stackoverflow.com/questions/7518080/how-to-force-visual-studio-debugger-to-skip-specific-exceptions – user1666620 Feb 23 '16 at 14:38
  • @user1666620, I don't want to skip specific exception. What I **would like** is some kind of property attribute... or rather compiler directive which tells to VS something like "please, when running this method in VS, ignore `BlablablaException`". That would be perfect, because I can apply it locally without having *side-effect* and necessity to manage exceptions (which seems I am currently trying to avoid). – Sinatr Feb 23 '16 at 15:18

1 Answers1

3

You can choose on what exception Visual Studio break by pressing 'CTRL + D + E' or hit "Debug" Menu, Windows and Exception Settings (see MSDN for more infos : https://msdn.microsoft.com/en-us/library/x85tt0dd.aspx)

Thent uncheck the exceptions you don't want to see (for converters, just uncheck CLR exceptions)

After that, just pay attention to the Output Window for that kind of exceptions...

cdie
  • 4,014
  • 4
  • 34
  • 57