gpt4 book ai didi

c# - 转换器应该抛出任何类型的异常吗?

转载 作者:太空狗 更新时间:2023-10-29 21:45:57 25 4
gpt4 key购买 nike

今天我遇到了一个错误,应用程序开始抛出多个异常(多个消息框)。应用程序使用 DispatcherUnhandledException。

在调查过程中,我发现如果转换器的参数为 NULL,则用于格式化 dataGrid 中的日期和时间的转换器会抛出 FormatException。

是否建议在任何情况下从转换器中抛出异常?

最佳答案

According to MSDN , 不:

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.

也就是说,当不支持 ConvertConvertBack 方法时,我个人使用 NotSupportedException

关于c# - 转换器应该抛出任何类型的异常吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11782205/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com