throw dedicated exception for invalid data

This commit is contained in:
Andreas Schildbach 2012-09-06 14:35:50 +02:00
parent 7ed8819fbb
commit f326933269
2 changed files with 50 additions and 3 deletions

View file

@ -64,6 +64,7 @@ import de.schildbach.pte.dto.QueryDeparturesResult;
import de.schildbach.pte.dto.ResultHeader;
import de.schildbach.pte.dto.StationDepartures;
import de.schildbach.pte.dto.Stop;
import de.schildbach.pte.exception.InvalidDataException;
import de.schildbach.pte.exception.ParserException;
import de.schildbach.pte.exception.ProtocolException;
import de.schildbach.pte.exception.SessionExpiredException;
@ -1552,11 +1553,11 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
if (year == 0)
return false;
if (year < 1900 || year > 2100)
throw new IllegalArgumentException("invalid year: " + year);
throw new InvalidDataException("invalid year: " + year);
if (month < 0 || month > 11)
throw new IllegalArgumentException("invalid month: " + month);
throw new InvalidDataException("invalid month: " + month);
if (day < 1 || day > 31)
throw new IllegalArgumentException("invalid day: " + day);
throw new InvalidDataException("invalid day: " + day);
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH, month);

View file

@ -0,0 +1,46 @@
/*
* Copyright 2012 the original author or authors.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.schildbach.pte.exception;
/**
* @author Andreas Schildbach
*/
public class InvalidDataException extends ParserException
{
public InvalidDataException()
{
super();
}
public InvalidDataException(final String message)
{
super(message);
}
public InvalidDataException(final String message, final Throwable cause)
{
super(message);
super.initCause(cause);
}
public InvalidDataException(final Throwable cause)
{
super(cause == null ? null : cause.toString());
super.initCause(cause);
}
}