title: How to handle exceptions in a FacesConverter?
body: <p>When the date format is not correct (for example when I manually post 13,02,2018 instead of 13.02.2018 and also other incorrect dates such as 13.02.999) the app crashes. How can I fix it? (the manual input is important, i can`t just disable it).</p>
  
  <p>XHTML:</p>
  
  <pre><code>&lt;rich:calendar enableManualInput="true" datePattern="dd.MM.yyyy"
      value="#{myBean.data.myDate}"&gt;
      &lt;f:converter converterId="mydate"/&gt;
  &lt;/rich:calendar&gt;
  </code></pre>
  
  <p>Converter:</p>
  
  <pre><code>@FacesConverter("mydate")
  public class LocalDateConverter implements Converter {
      private static final DateTimeFormatter formatter;
      static {
          formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy");
          formatter.withLocale(new Locale("ru"));
      }
      @Override
      public Object getAsObject(FacesContext context, UIComponent component, String value) {
          return LocalDate.parse(value, formatter); 
      }
  
      @Override
  public String getAsString(FacesContext context, UIComponent component, Object value) {
      if (value == null) {
          return "";
      } else if (value instanceof LocalDate) {
          return ((LocalDate) value).format(formatter);
      } else if (value instanceof LocalDateTime) {
          return ((LocalDateTime) value).format(formatter);
      } else {
          throw new IllegalArgumentException("Value is not java.time.LocaleDate");
      }
  }
  </code></pre>