public class InvalidDataException
extends java.lang.Exception
An InvalidDataException can be thrown as an exception in the usual way, e.g.,
throw new InvalidDataException( "Your imput data is invalid" );
However, an instance of InvalidDataException can also be used to collect a list of input data errors. You can throw the existing InvalidDataException at this point and the detailed messages will be available to the code which catches the error.
Example:
InvalidDataException ide = new InvalidDataException();
lineNumber = 0;
...
// If an input line has a data error, add a descriptive message to ide
ide.addMessage( "Invalid input in line " + lineNumber );
...
if ( ide.hasMessages() )
{
throw ide;
}
Modifier and Type | Field and Description |
---|---|
protected java.util.List<java.lang.String> |
errorMessages
List to hold error messages.
|
Constructor and Description |
---|
InvalidDataException()
Create empty data exception.
|
InvalidDataException(java.lang.String description)
Create data exception with error description.
|
Modifier and Type | Method and Description |
---|---|
void |
addMessage(java.lang.String errorMessage)
Add error message to list of errors.
|
java.util.List<java.lang.String> |
getMessages()
Get list of error messages.
|
boolean |
hasMessages()
Check there are any error messages.
|
protected java.util.List<java.lang.String> errorMessages
public InvalidDataException()
public InvalidDataException(java.lang.String description)
description
- Description of error.public void addMessage(java.lang.String errorMessage)
errorMessage
- The message to add to the list.public java.util.List<java.lang.String> getMessages()
public boolean hasMessages()