<分区>
我想知道是否建议使用 ApplicationException
来在用户违反某些业务规则时返回应用程序错误。例如:
public void validate(string name, string email)
{
int count1 = (from p in context.clients
where (p.name == clients.name)
select p).Count();
if (count1 > 0)
throw new ApplicationException("Your name already exist in the database");
int count2 = (from p in context.clients
where (p.email == clients.email)
select p).Count();
if (count2 > 0)
throw new ApplicationException("Your e-mail already exist in the database");
}
这是好策略还是坏策略?如果不是,什么是更好的方法?