Class ObjectParser.Exception

All Implemented Interfaces:
Serializable
Enclosing interface:
ObjectParser<T>

public static class ObjectParser.Exception extends IllegalArgumentException
Exception class for ObjectParser errors. This class provides access methods to recover the string that was being parsed and the offset into the string that is associated with the error.
See Also:
  • Constructor Details

    • Exception

      public Exception(String msg, String input, int offset)
      Constructor.
      Parameters:
      msg - a message describing this exception
      input - the input string
      offset - an offset into the string indicating where an error occurred; -1 if there is no specific offset
    • Exception

      public Exception(String msg, String filename, String input, int offset)
      Constructor with a file name.
      Parameters:
      msg - a message describing this exception
      filename - the name of the input
      input - the input string
      offset - an offset into the string indicating where an error occurred; -1 if there is no specific offset
    • Exception

      public Exception(String msg, Throwable cause, String input, int offset)
      Constructor with a cause.
      Parameters:
      msg - a message describing this exception
      cause - the Trowable that caused this exception
      input - the input string
      offset - an offset into the string indicating where an error occurred; -1 if there is no specific offset
    • Exception

      public Exception(String msg, Throwable cause, String filename, String input, int offset)
      Constructor with a file name and cause.
      Parameters:
      msg - a message describing this exception
      cause - the Trowable that caused this exception
      filename - the name of the input
      input - the input string
      offset - an offset into the string indicating where an error occurred; -1 if there is no specific offset
  • Method Details

    • addTrace

      public void addTrace(String filename, String input, int offset)
      Add additional elements for a stack trace.
      Parameters:
      filename - the name of the input
      input - the input string
      offset - an offset into the string indicating where an error occurred; -1 if there is no specific offset
    • getInput

      public String getInput()
      Get the input string for which the error occurred.
      Returns:
      the string
    • getFileName

      public String getFileName()
      Get the file name.
      Returns:
      the file name; null if there is none
    • getOffset

      public int getOffset()
      Get the offset into the input string for the location at which an error occurred.
      Returns:
      the offset; -1 if none is known
    • getPlainMessage

      public String getPlainMessage()
      Get the message as it was provided to this exception's constructor.
      Returns:
      the message.
    • setPrefix

      public void setPrefix(String prefix)
      Set the text that should precede each line of an error message. The method assumes that the message used to create this exception is on a single line.
      Parameters:
      prefix - the prefix
    • getPrefix

      public String getPrefix()
      Get the prefix.
      Returns:
      the prefix; null if it is not defined or if it is an empty string
    • showLocation

      public void showLocation(boolean mode)
      Indicate if a line showing the location of an error message should be added.
      Parameters:
      mode - true if a location should be added; false otherwise
    • getMessage

      public String getMessage()
      Get the message for this exception. The message will be annotated by adding a prefix, which can be set by calling setPrefix(String), and appending lines, each starting with the prefix, that contain a line from an input file or string, and a pointer indicating where in the line the error was detected. The first line will include a filename (if provided) and a line number.
      Overrides:
      getMessage in class Throwable
      Returns:
      the annotated message
    • getMessage

      public String getMessage(String prefix, boolean verbose, boolean showLocation)
      Get the error message with an explicitly provided prefix. The prefix will start each line of the message.
      Parameters:
      prefix - the prefix
      verbose - true if fully-qualified class names should be shown; false for just the final component of the class name
      showLocation - true to show the location for an error message; false otherwise
      Returns:
      the error message
    • wasThrown

      public boolean wasThrown()
      Determine if the exception was due to an explicit throw. ESP and ExpressionParser have 'throw' statement that will generate an exception.
      Returns:
      true if the exception was due to a throw statement, false otherwise