Class DataException

java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
com.northconcepts.datapipeline.core.DataException
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
ParseException

public class DataException extends RuntimeException
Indicates an error has occurred during the course of execution. DataException retrofits RuntimeException with the ability to contain properties and to prepend text to the message after construction.
See Also:
  • Constructor Details

    • DataException

      public DataException()
      Constructs a new exception.
    • DataException

      public DataException(String message)
      Constructs a new exception with the specified detail message.
    • DataException

      public DataException(Throwable cause)
      Constructs a new exception with the specified cause.
    • DataException

      public DataException(String message, Throwable cause)
      Constructs a new exception with the specified detail message and cause.
  • Method Details

    • wrap

      public static DataException wrap(String message, Throwable exception)
      Converts an exception to a DataException and prefixes the original message with the specified text. If the supplied exception is an instanceof DataException, it will be returned, otherwise it will be nested inside a DataException. In either case the result message will be prefixed with the supplied text.
      Parameters:
      message - the text to prefix to the original message
      exception - the exception to convert
      Returns:
      the converted exception
    • wrap

      public static DataException wrap(Throwable exception)
      Converts an exception to a DataException. If the supplied exception is an instanceof DataException, it will be returned, otherwise it will be nested inside a DataException.
      Parameters:
      exception - the exception to convert
      Returns:
      the converted exception
    • wrap

      public static DataException wrap(Throwable e, DataExceptionContributor... contributors)
      Wraps the exception as wrap(Throwable) does and adds the properties of each non-null contributor.
    • wrap

      public static DataException wrap(Throwable e, String namePrefix, DataExceptionContributor... contributors)
      Wraps the exception as wrap(Throwable) does and adds the properties of each non-null contributor, using namePrefix as the start of their keys.
    • get

      public Object get(String name)
      Returns the value mapped to the specified key or null.
    • getAsString

      public String getAsString(String name)
      Returns the value mapped to the specified key as a String or null.
    • getAsInteger

      public int getAsInteger(String name)
      Returns the value mapped to the specified key as an int or throws NullPointeException.
    • getAsLong

      public long getAsLong(String name)
      Returns the value mapped to the specified key as a long or throws NullPointeException.
    • getAsDouble

      public double getAsDouble(String name)
      Returns the value mapped to the specified key as a double or throws NullPointeException.
    • getAsBoolean

      public boolean getAsBoolean(String name)
      Returns the value mapped to the specified key as a boolean or throws NullPointeException.
    • getAsDatetime

      public Date getAsDatetime(String name)
      Returns the value mapped to the specified key as a Date or null.
    • set

      public DataException set(String name, Map<?,?> value)
      Maps a java.util.Map to the specified key, overwriting any previous association.
      Parameters:
      name - key with which the specified value is to be associated.
      value - value to be associated with the specified key.
      Returns:
      this exception
    • set

      public DataException set(String name, Collection<?> value)
      Maps a collection to the specified key, overwriting any previous association.
      Parameters:
      name - key with which the specified value is to be associated.
      value - value to be associated with the specified key.
      Returns:
      this exception
    • set

      public DataException set(String name, Object value)
      Maps a value to the specified key, overwriting any previous association.
      Parameters:
      name - key with which the specified value is to be associated.
      value - value to be associated with the specified key.
      Returns:
      this exception
    • set

      public DataException set(String name, char value)
      Maps a character value to the specified key, overwriting any previous association. If the character represents a special, non-printable value (end-of-file, new-line, carriage return, etc.), it will be converted to a human-readable string.
      Parameters:
      name - key with which the specified value is to be associated.
      value - value to be associated with the specified key.
      Returns:
      this exception
    • set

      public DataException set(String name, int value)
      Maps an int value to the specified key, overwriting any previous association.
      Parameters:
      name - key with which the specified value is to be associated.
      value - value to be associated with the specified key.
      Returns:
      this exception
    • set

      public DataException set(String name, long value)
      Maps a long value to the specified key, overwriting any previous association.
      Parameters:
      name - key with which the specified value is to be associated.
      value - value to be associated with the specified key.
      Returns:
      this exception
    • set

      public DataException set(String name, double value)
      Maps a double value to the specified key, overwriting any previous association.
      Parameters:
      name - key with which the specified value is to be associated.
      value - value to be associated with the specified key.
      Returns:
      this exception
    • set

      public DataException set(String name, boolean value)
      Maps a boolean value to the specified key, overwriting any previous association.
      Parameters:
      name - key with which the specified value is to be associated.
      value - value to be associated with the specified key.
      Returns:
      this exception
    • getFieldName

      public String getFieldName()
      Returns the field name associated with this exception.
    • setFieldName

      public DataException setFieldName(String fieldName)
      sets the field name associated with this exception.
      Returns:
      this exception
    • getRecord

      public Record getRecord()
      Returns the record associated with this exception.
    • setRecord

      public DataException setRecord(Record record)
      Sets the record associated with this exception.
      Returns:
      this exception
    • getProperties

      public Map<String,Object> getProperties()
      Returns the values associated with this exception as a Map.
      Returns:
      a non-null array of value names.
      See Also:
    • getPropertiesAsString

      public String getPropertiesAsString()
      Returns the properties as name=[value] lines sorted by name, or null if there are none.
    • prefixMessageWith

      public DataException prefixMessageWith(String message)
      Prefixes this exception's message with the specified text.
      Parameters:
      message - the text to prefix to the original message
      Returns:
      this exception
    • getMessage

      public String getMessage()
      Returns the detail message string of this exception along with any prefixed text. This method is equivalent to calling getOriginalMessageWithPrefix().
      Overrides:
      getMessage in class Throwable
    • getMessageWithProperties

      public String getMessageWithProperties()
      Returns the detail message string of this exception along with any prefixed text and properties (name-value pairs).
    • printStackTrace

      public void printStackTrace(PrintStream s)
      Prints this throwable and its backtrace to the specified print stream.
      Overrides:
      printStackTrace in class Throwable
      Parameters:
      s - PrintStream to use for output
    • printStackTrace

      public void printStackTrace(PrintWriter s)
      Prints this throwable and its backtrace to the specified print writer.
      Overrides:
      printStackTrace in class Throwable
      Parameters:
      s - PrintWriter to use for output
    • isCauseInterruptedException

      public boolean isCauseInterruptedException()
      Returns true if the nested exception indicates that a thread was interrupted.
      See Also:
    • isCausedBy

      public boolean isCausedBy(Class<? extends Throwable> causeClass)
      Returns true if this exception was caused by (or one of its nested exceptions was caused by) the specified exception.
    • getExceptionFromCause

      public <T extends Throwable> T getExceptionFromCause(Class<T> causeClass)
      Returns causeClass if this exception was caused by (or one of its nested exceptions was caused by) the specified exception.
    • getRootCause

      public Throwable getRootCause()
      Returns the root cause of this throwable or this if the cause is nonexistent or unknown.
    • toString

      public String toString()
      Overrides:
      toString in class Throwable
    • toOriginalString

      public String toOriginalString()
      Returns the class name and message without the properties that toString() appends.
    • contributeExceptionProperties

      public DataException contributeExceptionProperties(DataExceptionContributor... contributors)
      Adds the properties of each non-null contributor to this exception and returns it.