title: Java Enum.valueOf() efficiency when value does not exist
body: <p>Which would you consider more efficient?</p>
  
  <p>The use of 'WeekDay' is just an example:</p>
  
  <pre><code>public enum WeekDay {
      MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY;
  }
  </code></pre>
  
  <p>Loop through and verify day string first:</p>
  
  <pre><code>public void parseString(String line) {
      String[] tokens = line.split();
      String day = tokens[1]; // day 'should' always be a weekday
      if (isValidWeekDay(day)) {
          WeekDay weekDay = WeekDay.valueOf(day); // won't throw exception
          ...
      } else {
          throw new InvalidWeekDayException(day); // subclass of RuntimeException
      }
  }
  private boolean isValidWeekDay(String day) {
      for (WeekDay weekDay : WeekDay.values()) {
          if(weekDay.toString().equals(day))
             return true;
      }
      return false;
  }
  </code></pre>
  
  <p>Or since in 99.99% of cases, day will be correct:</p>
  
  <pre><code>public void parseString(String line) {
      String[] tokens = line.split();
      String day = tokens[1]; // day 'should' always be a weekday
      try {
          WeekDay weekDay = WeekDay.valueOf(day); // might throw exception
          ...
      } catch (IllegalArgumentException e) {
          throw new InvalidWeekDayException(day, e);
      }
  }
  </code></pre>
  
  <hr>
  
  <p><strong>Update</strong>: </p>
  
  <p>To clarify, the input string will come from a client application, rather than a user. So in other words, it would be a bug to recieve a non workday in this example.    </p>