混淆
我正在尝试为用户输入创建验证策略。但是我一直遇到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
应该像
class OverflowAction : Exception
{
// ...
}
您可能会使OverflowAction
与OverflowException
...