In your code example, you would be better off throwing an ArgumentNullException
it is more meaningful. ApplicationException
does not really give the caller any indication as to what the exception means.
As for the last check for the valid email, either an ArgumentException
or a custom exception class that inherits from Argument
exception would be best.
public void update(string name, string email)
{
if (string.IsNullOrEmpty(name))
{
throw new ArgumentNullException(nameof(name), "Type your name");
}
if (string.IsNullOrEmpty(email))
{
throw new ArgumentNullException(nameof(email), "Type your e-mail");
}
if (isValidEmail(email))
{
throw new ArgumentException(nameof(name), "Invalid e-mail");
}
//Save in the database
}