I'd like to know if the use of ApplicationException
is recommended to return application errors when a user breaks some business rule. For example:
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");
}
Is it a good or bad strategy? If isn't, what would be a better approach?