title: Should exceptions be used for form validation?
body: <p>This might be a n00bish question, but whatever. Is okay to use exceptions for form validation? Let's say I have a form which asks users for their name and email, is right to do the following?</p>
  
  <pre><code>try {
      if (empty($_POST["name"])) {
          throw new UserRegistrationException("Your name cannot be empty.");
      }
  
      if (filter_var($_POST["email"])) {
          throw new UserRegistrationException("Invalid email");
      }
  
      // Save new user into database
  } catch (UserRegistrationException $e) {
      // Show errors on screen
  }
  </code></pre>
  
  <p>Also -if this is in fact the correct way to do it- if the user submits <strong>both</strong> an empty name and an invalid email, would both of the exceptions execute or only the one that appears first (the name one in this case)?</p>
  
  <p>I'm using <a href="http://www.php.net/" rel="noreferrer">PHP</a> by the way.</p>