Class ParseException

  • All Implemented Interfaces:
    Serializable

    public class ParseException
    extends RuntimeException
    Unchecked failure to parse Java source, carrying the offending position and, when available, the source text so the message can show the line with a caret.
    See Also:
    Serialized Form
    • Constructor Detail

      • ParseException

        public ParseException​(String message,
                              SourcePosition position,
                              String source)
        Creates a failure with source text for context rendering.
        Parameters:
        message - what went wrong
        position - where it went wrong, or null
        source - the full source text, or null to omit the context excerpt
      • ParseException

        public ParseException​(String message,
                              SourcePosition position)
        Creates a failure with no source text, so the message carries only the position.
        Parameters:
        message - what went wrong
        position - where it went wrong, or null
      • ParseException

        public ParseException​(String message,
                              Token token,
                              String source)
        Creates a failure positioned at a token, with source text for context rendering.
        Parameters:
        message - what went wrong
        token - the offending token
        source - the full source text, or null to omit the context excerpt
        Throws:
        NullPointerException - if the token is null
      • ParseException

        public ParseException​(String message,
                              Token token)
        Creates a failure positioned at a token, with no source text.
        Parameters:
        message - what went wrong
        token - the offending token
        Throws:
        NullPointerException - if the token is null
    • Method Detail

      • getPosition

        public SourcePosition getPosition()
        Returns:
        the position
      • getSource

        public String getSource()
        Returns:
        the source
      • getLine

        public int getLine()
        Returns:
        the 1-based line, or 0 when no position was recorded
      • getColumn

        public int getColumn()
        Returns:
        the 1-based column, or 0 when no position was recorded
      • getFormattedMessage

        public String getFormattedMessage()
        Renders the message, the position when known, and - if the source text was supplied - the offending line with a caret under the column.
        Returns:
        the multi-line report