如何修复 C# 中 wpf 项目的"Type caught or thrown must be derived from system.exception"错误?



我正在尝试为用户输入创建验证策略。但是我一直遇到CS0155错误。

我尝试过一个例外,但没有摆脱错误。

    catch (OverflowAction)
            {
                Debug.WriteLine(
                    "{0}.Validate: Int32 overflow ("{1}").",
                    GetType(), str);
                string errmsg = Properties.Resources.OverflowError;
                return new ValidationResult(false, errmsg);
               //throw new NotImplementedException();
            }

我希望验证器能捕获异常并返回错误消息。

此错误表明您的OverflowAction类不会从Exception继承(或派生一个(。

请参阅CS0155错误文档。

只有从系统派生的数据类型可以传递到捕获块中。

OverflowAction应该像

一样looke
class OverflowAction : Exception
{
    // ...
}

您可能会使OverflowActionOverflowException ...

混淆

相关内容

最新更新