调试期间不要中断。

5
这个问题似乎与之前的一个问题非常相似:previous,但是案例有点不同(也许更好地展示了问题),虽然目标相同。
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); }
    }

当这段代码独立运行时,对于输入的 123 ,会在 TextBox 周围显示红色边框(字段值不会更改)。输入 red#FF0000 将删除边框并更新字段值。
问题:当在 Visual Studio 下运行程序时,输入 123 会在 ConvertFromString 上抛出异常(顺带提一下,这是未记录的):

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

Additional information: Token is not valid.

如何防止 Visual Studio 中断程序执行?

@user1666620,这不是一个错误,我想避免执行被中断。 - Sinatr
你能否处理一下异常,这样就不会有问题了吗? - Jacobr365
可能是重复的问题:如何让Visual Studio忽略异常? - user1666620
在 catch 块中只需绘制红色轮廓。 - Jacobr365
1
@user1666620,第一次,第二次,第三次,...,100500次?目前有几个地方我正在使用“ExceptionValidationRule”,这让我感到不舒服。这就是为什么我来这里的原因。 - Sinatr
显示剩余7条评论
1个回答

3
您可以按 'CTRL + D + E' 或者点击 "Debug" 菜单,选择 Windows 和 Exception Settings 来设置 Visual Studio 的异常提示方式(更多信息请参考 MSDN:https://msdn.microsoft.com/en-us/library/x85tt0dd.aspx)。然后取消勾选您不想看到的异常(对于转换器,请取消勾选 CLR 异常)。之后,只需关注输出窗口以获取该类型的异常信息即可...

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接