Is this return style acceptable? Would the code be more readable if I assigned the MonthDay.parse()
return value to a variable and returned that variable on the last line?
Also, is it a bad idea to both log and rethrow inside a catch block?
/**
* Parses showing date from the header text.
*
* @throws PageStructureException if the date string does not conform to the expected format
*/
public MonthDay parseShowingDate( String date ) throws PageStructureException {
Preconditions.checkNotNull( date );
DateTimeFormatter matDTF = DateTimeFormat.forPattern( DATE_FORMAT );
String dayAndMonth = removeDayOfWeek( date );
try {
return MonthDay.parse( dayAndMonth, matDTF );
} catch ( IllegalArgumentException iae ) {
logger.error( "Could not parse MAT date {}, expected format [{}].", date, DATE_FORMAT );
throw new PageStructureException( iae );
}
}