Class TextParsingException

  • All Implemented Interfaces:
    java.io.Serializable
    Direct Known Subclasses:
    DataProcessingException

    public class TextParsingException
    extends java.lang.RuntimeException
    Exception type used provide information about any issue that might happen while parsing from a given input.

    It generally provides location information about where in the input a parsing error occurred.

    Author:
    uniVocity Software Pty Ltd - parsers@univocity.com
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      TextParsingException​(Context context, java.lang.String message, java.lang.Throwable cause)
      Creates a new exception with information about an error that occurred when parsing some input.
      TextParsingException​(ParsingContext context)
      Creates a new exception with information about an error that occurred when parsing some input.
      TextParsingException​(ParsingContext context, java.lang.String message)
      Creates a new exception with information about an error that occurred when parsing some input.
      TextParsingException​(ParsingContext context, java.lang.Throwable cause)
      Creates a new exception with information about an error that occurred when parsing some input.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      long getCharIndex()
      Returns the location of the last character read from before the error occurred.
      int getColumnIndex()
      Returns the column index where the exception occurred.
      protected java.lang.String getDetails()
      Subclasses must implement this method to return as much information as possible about the internal state of the parser/writer.
      protected java.lang.String getErrorDescription()
      Returns a generic description of the error.
      java.lang.String[] getHeaders()
      Returns the headers processed from the input, if any.
      long getLineIndex()
      Returns the line number where the exception occurred.
      java.lang.String getMessage()
      Returns a detailed message describing the error, and the internal state of the parser/writer.
      java.lang.String getParsedContent()
      Returns the last chunk of content parsed before the error took place
      long getRecordNumber()
      Returns the record number when the exception occurred.
      protected static java.lang.String printIfNotEmpty​(java.lang.String previous, java.lang.String description, java.lang.Object o)  
      static java.lang.String restrictContent​(int errorContentLength, java.lang.CharSequence content)  
      static java.lang.Object[] restrictContent​(int errorContentLength, java.lang.Object[] content)  
      protected java.lang.String restrictContent​(java.lang.CharSequence content)  
      protected java.lang.String restrictContent​(java.lang.Object content)  
      protected java.lang.Object[] restrictContent​(java.lang.Object[] content)  
      protected void setContext​(Context context)  
      void setErrorContentLength​(int errorContentLength)  
      protected java.lang.String updateMessage​(java.lang.String msg)
      Allows subclasses to alter the exception message that should be displayed to end users.
      • Methods inherited from class java.lang.Throwable

        addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • extractedIndexes

        protected int[] extractedIndexes
      • errorContentLength

        protected int errorContentLength
    • Constructor Detail

      • TextParsingException

        public TextParsingException​(Context context,
                                    java.lang.String message,
                                    java.lang.Throwable cause)
        Creates a new exception with information about an error that occurred when parsing some input.
        Parameters:
        context - the context of the parser when an error occurred
        message - message with details about the error
        cause - the cause of the error
      • TextParsingException

        public TextParsingException​(ParsingContext context,
                                    java.lang.String message)
        Creates a new exception with information about an error that occurred when parsing some input.
        Parameters:
        context - the context of the parser when an error occurred
        message - message with details about the error
      • TextParsingException

        public TextParsingException​(ParsingContext context,
                                    java.lang.Throwable cause)
        Creates a new exception with information about an error that occurred when parsing some input.
        Parameters:
        context - the context of the parser when an error occurred
        cause - the cause of the error
      • TextParsingException

        public TextParsingException​(ParsingContext context)
        Creates a new exception with information about an error that occurred when parsing some input.
        Parameters:
        context - the context of the parser when an error occurred
    • Method Detail

      • setContext

        protected void setContext​(Context context)
      • getErrorDescription

        protected java.lang.String getErrorDescription()
        Returns a generic description of the error. The result of this method is used by Throwable.getMessage() to print out a general description of the error before a detailed message of the root cause.
        Returns:
        a generic description of the error.
      • getDetails

        protected java.lang.String getDetails()
        Subclasses must implement this method to return as much information as possible about the internal state of the parser/writer. Use printIfNotEmpty(String, String, Object) to create a comma-separated list of relevant properties and their (non null) values. The result of this method is used by the Throwable.getMessage() method to print out these details after the error message.
        Returns:
        a String describing the internal state of the parser/writer.
      • getRecordNumber

        public long getRecordNumber()
        Returns the record number when the exception occurred.
        Returns:
        the record number when the exception occurred.
      • getColumnIndex

        public int getColumnIndex()
        Returns the column index where the exception occurred.
        Returns:
        the column index where the exception occurred.
      • getLineIndex

        public long getLineIndex()
        Returns the line number where the exception occurred.
        Returns:
        the line number where the exception occurred.
      • getCharIndex

        public long getCharIndex()
        Returns the location of the last character read from before the error occurred.
        Returns:
        the location of the last character read from before the error occurred.
      • getParsedContent

        public final java.lang.String getParsedContent()
        Returns the last chunk of content parsed before the error took place
        Returns:
        the last chunk of content parsed before the error took place
      • getHeaders

        public final java.lang.String[] getHeaders()
        Returns the headers processed from the input, if any.
        Returns:
        the headers processed from the input, if any.
      • getMessage

        public final java.lang.String getMessage()
        Returns a detailed message describing the error, and the internal state of the parser/writer.
        Overrides:
        getMessage in class java.lang.Throwable
        Returns:
        a detailed message describing the error
      • updateMessage

        protected java.lang.String updateMessage​(java.lang.String msg)
        Allows subclasses to alter the exception message that should be displayed to end users. By default the original message is kept unchanged.
        Parameters:
        msg - the original message
        Returns:
        the updated message.
      • printIfNotEmpty

        protected static java.lang.String printIfNotEmpty​(java.lang.String previous,
                                                          java.lang.String description,
                                                          java.lang.Object o)
      • restrictContent

        public static java.lang.String restrictContent​(int errorContentLength,
                                                       java.lang.CharSequence content)
      • restrictContent

        public static java.lang.Object[] restrictContent​(int errorContentLength,
                                                         java.lang.Object[] content)
      • setErrorContentLength

        public void setErrorContentLength​(int errorContentLength)
      • restrictContent

        protected java.lang.String restrictContent​(java.lang.CharSequence content)
      • restrictContent

        protected java.lang.String restrictContent​(java.lang.Object content)
      • restrictContent

        protected java.lang.Object[] restrictContent​(java.lang.Object[] content)