且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如果转换器抛出任何类型的异常?

更新时间:2023-01-01 09:52:16

根据MSDN 无:

数据绑定引擎没有赶上由
用户提供的转换器抛出的异常。由转换
方法抛出的任何异常,或由该
转换方法调用,被视为运行时错误方法抛出任何未捕获的异常。通过返回DependencyProperty.UnsetValue处理
预期的问题。

The data binding engine does not catch exceptions that are thrown by a user-supplied converter. Any exception that is thrown by the Convert method, or any uncaught exceptions that are thrown by methods that the Convert method calls, are treated as run-time errors. Handle anticipated problems by returning DependencyProperty.UnsetValue.

话虽这么说,我个人使用引发NotSupportedException 时,无论是转换 ConvertBack 不支持的方法。

That being said, personally I use the NotSupportedException when either the Convert or ConvertBack method is not supported.