Package com.opencsv.exceptions
Class CsvConstraintViolationException
- java.lang.Object
-
- java.lang.Throwable
-
- java.lang.Exception
-
- com.opencsv.exceptions.CsvException
-
- com.opencsv.exceptions.CsvConstraintViolationException
-
- All Implemented Interfaces:
java.io.Serializable
public class CsvConstraintViolationException extends CsvException
This exception is thrown when logical connections between data fields would be violated by the imported data.This can be for constraints like making certain a number is in a certain range, or it can even be thrown by code using opencsv when constraints outside of opencsv would be violated. An example of the latter is importing into a database when one of the field in the CSV is supposed to contain the primary key for a foreign table, but the foreign key cannot be satisfied.
This exception is not currently used by opencsv itself, since opencsv has no concept of what data consistency means in the context of the application using it. It is meant more for custom converters.
- Since:
- 3.8
- Author:
- Andrew Rucker Jones
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description CsvConstraintViolationException()
Default constructor, in case no further information is necessary or available.CsvConstraintViolationException(java.lang.Object sourceObject)
Constructor for setting the source object that triggered the constraint violation.CsvConstraintViolationException(java.lang.Object sourceObject, java.lang.String message)
Constructor for setting the source object and an error message.CsvConstraintViolationException(java.lang.String message)
Constructor with a simple text.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Object
getSourceObject()
Gets the object that would have caused a constraint violation.-
Methods inherited from class com.opencsv.exceptions.CsvException
getLine, getLineNumber, setLine, setLineNumber
-
-
-
-
Constructor Detail
-
CsvConstraintViolationException
public CsvConstraintViolationException()
Default constructor, in case no further information is necessary or available.
-
CsvConstraintViolationException
public CsvConstraintViolationException(java.lang.Object sourceObject)
Constructor for setting the source object that triggered the constraint violation.- Parameters:
sourceObject
- The offending source object
-
CsvConstraintViolationException
public CsvConstraintViolationException(java.lang.String message)
Constructor with a simple text.- Parameters:
message
- Human-readable error text
-
CsvConstraintViolationException
public CsvConstraintViolationException(java.lang.Object sourceObject, java.lang.String message)
Constructor for setting the source object and an error message.- Parameters:
sourceObject
- The offending source objectmessage
- Human-readable error text
-
-
Method Detail
-
getSourceObject
public java.lang.Object getSourceObject()
Gets the object that would have caused a constraint violation.sourceObject
is markedtransient
, becauseObject
is notSerializable
. If for any reason this exception is serialized and deserialized, this method will subsequently returnnull
.- Returns:
- The source object that triggered the constraint violation
-
-