Example usage for java.time.format DateTimeParseException addSuppressed

List of usage examples for java.time.format DateTimeParseException addSuppressed

Introduction

In this page you can find the example usage for java.time.format DateTimeParseException addSuppressed.

Prototype

public final synchronized void addSuppressed(Throwable exception) 

Source Link

Document

Appends the specified exception to the exceptions that were suppressed in order to deliver this exception.

Usage

From source file:de.jfachwert.rechnung.Rechnungsmonat.java

private static LocalDate guessLocalDate(String monat, DateTimeParseException ex) {
    String[] datePatterns = { "d-MMM-yyyy", "d-MM-yyyy", "yyyy-MMM-d", "yyyy-MM-d", "MMM-d-yyyy" };
    for (String pattern : datePatterns) {
        for (Locale locale : Locale.getAvailableLocales()) {
            try {
                return LocalDate.parse(monat, DateTimeFormatter.ofPattern(pattern, locale));
            } catch (DateTimeParseException ignored) {
                ex.addSuppressed(new IllegalArgumentException(
                        ignored.getMessage() + " / '" + monat + "' does not match '" + pattern + "'"));
            }/*from  ww  w.j a  v  a 2  s  .  c  om*/
        }
    }
    throw new InvalidValueException(monat, MONTH, ex);
}