我有一个绑定到ComboBox的属性
<ComboBox ItemsSource="{Binding AvailableTypes}"
SelectedValue="{Binding Kind, Mode=TwoWay}}"/>
Run Code Online (Sandbox Code Playgroud)
在属性设置器中,我在某些业务情况下抛出异常以中止设置属性.
public MyKind Kind
{
get { return kind; }
set
{
if (kind != value)
{
if (SomeRuleFailed(value))
throw new Exception("to be ate by binding code");
kind = value;
}
}
}
Run Code Online (Sandbox Code Playgroud)
它工作顺利,除了每次我引发异常时VS2010弹出的事实.是否有任何异常要提升或属性设置,以便调试器在后台保留?
您可以通过转到Debug> Exceptions来设置导致调试器中断的异常类型.取消对Common Language Runtime Exceptions的Thrown复选框或单独选择您的异常类型.
你不应该抛出一个Exception类的实例.你应该抛出一个派生自的类的实例Exception.
您可以创建自己的异常类(如果您有一些框架尚未涵盖的内容,则应该不习惯)然后您可以选择希望Visual Studio中断的异常.
一旦创建了异常类,转到Debug - > Exceptions ...然后选择要让调试器中断的异常.