目前,System.Windows.Data Error: 6 : 'StringFormat' converter failed to convert value '600' (type 'Decimal'); fallback value will be used, if available. BindingExpression:Path=MyInt; DataItem='ViewModel' (HashCode=37975124); target element is 'TextBox' (Name='MyIntTextBox'); target property is 'Text' (type 'String') FormatException:'System.FormatException: Input string was not in a correct format.
at System.Text.StringBuilder.AppendFormatHelper(IFormatProvider provider, String format, ParamsArray args)
at System.String.FormatHelper(IFormatProvider provider, String format, ParamsArray args)
at System.String.Format(IFormatProvider provider, String format, Object[] args)
at System.Windows.Data.BindingExpression.ConvertHelper(IValueConverter converter, Object value, Type targetType, Object parameter, CultureInfo culture)'
类抓住了两个不同的异常:
我的问题:
DataIntegrityViolationException
例外?谢谢
答案 0 :(得分:1)
根据documentation,DataIntegrityViolationException
类是DuplicateKeyException
class的子类。以下是DuplicateKeyException
的文档所说的内容:
尝试插入或更新数据时会抛出异常 违反主键或唯一约束。
因此,如果要区分这两者,可以提供两个单独的catch
块并相应地处理异常,例如:
try{
// Some operation
}catch (DuplicateKeyException dke){
// Handle duplicate key
}catch (DataIntegrityViolationException dve){
// Handle data integrity violation
}