title: Java which assertion error to catch
body: <p>I'm practicing a bit of Java SE 7 on my own and came across the following problem.  I've written a public static void function <strong>ValidDate</strong> that takes in three strings and only throws an assertion error if the date is not valid.  <strong>ValidDate</strong> uses two string arrays (<em>MONTHS</em> and <em>DAYS</em>) as libraries to validate the given date. <strong>ValidDate</strong> also has a unique assert expression at the end of each assertion test:</p>
  
  <pre><code>public static void ValidDate(String month, String day, String year){
      boolean validday = false;
      boolean validmonth = false;
      boolean validyear = true;
  
      try{
          Integer.parseInt(year);
      }catch(NumberFormatException e){
          validyear = false;
      }
      assert(validyear): "Error: year entry not written in integers.";
  
  
      for(String m:MONTHS){
          if(m.equals(month)){
              validmonth = true;
          }
      }
      assert (validmonth): "Error: month entry is not valid; must be an"
              + " integer between (0)1 and 12.";
  
      ...
  }
  </code></pre>
  
  <p>My intent is to add <strong>ValidDate</strong> as a help function for a <em>DOB</em> setter (<strong>SetDOB</strong>) for my public class <em>Person</em>.  The implementation would be to have <strong>ValidDate</strong> throw an exception when an invalid <em>DOB</em> is entered in the setter, and <strong>SetDOB</strong> would then output a message that the entered <em>DOB</em> was unacceptable and not change the current <em>DOB</em> value:</p>
  
  <pre><code>public void SetDOB(String newDOB){
      String[] dates = newDOB.split("/");
      boolean validdate = true;
      if(dates.length == 3){
          try{
              ValidDate(dates[0],dates[1],dates[2]);
          }
          catch(AssertionError e){
              System.out.println("Error: ValidDate threw an assert error.");
              validdate = false;
          }
          if(validdate){
              DOB = newDOB;
          }
      }
      else{
          System.out.println("Please enter a valid DOB of the form: Month/Day"
                  + "/Year using integers.");
      }
  }
  </code></pre>
  
  <p>When I attempted to run <strong>SetDOB</strong> with an invalid <em>DOB</em>, however, <strong>ValidDate</strong> would not throw an AssertionError for <em>SetDOB</em> to catch.  No error messages were output either.  I suspect that the cause of this is related to my use of try-catch statements in either <strong>ValidDate</strong> or <strong>SetDOB</strong>.  However, I may have made a different mistake without realizing it as well.  I want someone to explain what I did wrong and how to accomplish my intended task correctly.  If someone else has already answered this or a similar question, then please add in a link to their post.  I may also remove this post if I find it redundant when encountering the linked post.</p>