7

I have an ExceptionValidationRule on my TextBox:

<Window.Resources>
    <Style x:Key="textStyleTextBox" TargetType="TextBox">
        <Style.Triggers>
            <Trigger Property="Validation.HasError" Value="true">
                <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}" />
            </Trigger>
        </Style.Triggers>
    </Style>
</Window.Resources>

<TextBox x:Name="myTextBox"
    {Binding Path=MyProperty, ValidatesOnExceptions=True}"
    Style="{StaticResource ResourceKey=textStyleTextBox}" />

and MyProperty looks like that:

private int myProperty;

public int MyProperty
{
    get { return myProperty; }
    set
    {
        if(value > 10)
            throw new ArgumentException("LOL that's an error");
        myProperty = value;
    }
}

In DEBUG mode, application crashes with unhandled exception "LOL that's an error" (WPF Binding Engine doesn't catch this and I think it should...).

In RELEASE mode, everything works fine.

Can someone tell me, why the hell is this happening? And how can I fix this?

1
  • Do you have an UnhandledException event attached?
    – Krimson
    Commented Dec 8, 2010 at 14:09

1 Answer 1

8

The solution is not so obvious nor well documented, but simple enough. The reason Visual Studio breaks for exceptions when running in debug mode is because it's configured that way.

In the Debug menu, select "Exceptions...". In this dialog you control how VS handles exceptions. Simply uncheck "User-unhandled" for "Common Language Runtime Exceptions", press OK and run your project again.

2
  • Thank you so much..I've been breaking my head due to the same problem. Thanks a lot
    – Shee
    Commented Aug 24, 2012 at 8:46
  • So then what happens an exception is fired and WPF doesn't gracefully catch it. Does the Debugger still work then? Commented Mar 28, 2014 at 10:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.