title: Java Unparseable Date difference in formats
body: <p>How to differentiate between data-entry being (a) invalid date or (b) invalid format?</p>
  
  <p>I have the following code for handling date inputs from an text file.</p>
  
  <pre><code>    public boolean dateIsValid(String date) {
          DateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");          
          formatter.setLenient(false);
              try {
                  Date dateParsed = (Date) formatter.parse(date);
              } catch (ParseException e) {
                  e.printStackTrace();
              }
              return false;
  
          }
  </code></pre>
  
  <p>I have everything working as I want it to. The only problem I have is I am unable to differentiate the different parse exceptions thrown. For example:</p>
  
  <p>if String date = 18/10/2012 --> <code>java.text.ParseException: Unparseable date: "18/10/2012"</code> 
  <br>if String date = 2-12-2001  --> <code>java.text.ParseException: Unparseable date: "2-12-2001"</code></p>
  
  <p>As you can see, both the wrong formats throw the same error. How can I differentiate them so that I can handle them differently?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>To be more precise, in case of date 18/10/2012, I should throw an invalid date error and in the case of date 2-12-2001, I need to throw an invalid format exception. I dont need to handle different formats. I just need a way of getting different exceptions for these two different cases. </p>