title: Java - Specific validation error
body: <p>I want to validate a class called <code>Person</code>. I could write something like:</p>
  
  <pre><code>class Person {
    ...
    public boolean isValid() {
      return (name != null &amp;&amp; age &gt; 0);
    }
  }
  </code></pre>
  
  <p>However, in my presentation layer, I want to show the user the specific reason for why the validation failed.</p>
  
  <p>The solutions I've come up with are:</p>
  
  <ol>
  <li>Throw exceptions within <code>isValid()</code> specific to the error</li>
  <li>Make <code>isValid()</code> return a <code>PersonValidationError</code> enum instead of a boolean</li>
  <li>Duplicate the validation logic in the presentation layer</li>
  </ol>
  
  <p>I want to know what the best way of handling this is. Also, how does the Java standard library deal with this kind of situation?</p>