Skip to content

Commit

Permalink
Error handling of toString
Browse files Browse the repository at this point in the history
  • Loading branch information
Lojjs committed Apr 5, 2018
1 parent ecc0079 commit 5694fcd
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ private int compareNamedZonesWithMapping( ZoneId thisZone, ZoneId thatZone )
@Override
public String prettyPrint()
{
return value.format( DateTimeFormatter.ISO_DATE_TIME );
return assertPrintable( () -> value.format( DateTimeFormatter.ISO_DATE_TIME ) );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ public <E extends Exception> void writeTo( ValueWriter<E> writer ) throws E
@Override
public String prettyPrint()
{
return value.format( DateTimeFormatter.ISO_DATE );
return assertPrintable( () -> value.format( DateTimeFormatter.ISO_DATE ) );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ public <E extends Exception> void writeTo( ValueWriter<E> writer ) throws E
@Override
public String prettyPrint()
{
return value.format( DateTimeFormatter.ISO_LOCAL_DATE_TIME );
return assertPrintable( () -> value.format( DateTimeFormatter.ISO_LOCAL_DATE_TIME ) );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public <E extends Exception> void writeTo( ValueWriter<E> writer ) throws E
@Override
public String prettyPrint()
{
return value.format( DateTimeFormatter.ISO_LOCAL_TIME );
return assertPrintable( () -> value.format( DateTimeFormatter.ISO_LOCAL_TIME ) );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1449,6 +1449,18 @@ static <TEMP extends Temporal> TEMP assertParsable( Supplier<TEMP> func )
}
}

static String assertPrintable( Supplier<String> func )
{
try
{
return func.get();
}
catch ( DateTimeException e )
{
throw new TemporalParseException( e.getMessage(), e );
}
}

static <TEMP extends Temporal> TEMP assertValidArithmetic( Supplier<TEMP> func )
{
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ public <E extends Exception> void writeTo( ValueWriter<E> writer ) throws E
@Override
public String prettyPrint()
{
return value.format( DateTimeFormatter.ISO_TIME );
return assertPrintable( () -> value.format( DateTimeFormatter.ISO_TIME ) );
}

@Override
Expand Down

0 comments on commit 5694fcd

Please sign in to comment.