Package org.codehaus.groovy.syntax
Class SyntaxException
java.lang.Object
java.lang.Throwable
java.lang.Exception
org.codehaus.groovy.GroovyException
org.codehaus.groovy.syntax.SyntaxException
- All Implemented Interfaces:
Serializable,GroovyExceptionInterface
- Direct Known Subclasses:
IncorrectTypeHintException,TokenException
Base exception class indicating a syntax error detected during parsing.
Captures source location information (line and column numbers) where the
error occurred to facilitate debugging and error reporting.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionSyntaxException(String message, int startLine, int startColumn) Constructs a SyntaxException with line and column information.SyntaxException(String message, int startLine, int startColumn, int endLine, int endColumn) Constructs a SyntaxException with complete position range information.SyntaxException(String message, Throwable cause, int startLine, int startColumn) Constructs a SyntaxException with a cause exception.SyntaxException(String message, Throwable cause, int startLine, int startColumn, int endLine, int endColumn) Constructs a SyntaxException with a cause exception and complete position information.SyntaxException(String message, ASTNode node) Constructs a SyntaxException from an AST node's position information. -
Method Summary
Modifier and TypeMethodDescriptionintReturns the ending column number of the error.intReturns the ending line number of the error.intgetLine()Returns the starting line number of the error.Returns the error message with location information appended.Returns the original error message without location information.Returns the optional source locator string.intReturns the starting column number of the error.intReturns the starting line number of the error.voidsetSourceLocator(String sourceLocator) Sets an optional source locator string (e.g., file path, URL).Methods inherited from class org.codehaus.groovy.GroovyException
isFatal, setFatalMethods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Constructor Details
-
SyntaxException
Constructs a SyntaxException from an AST node's position information.- Parameters:
message- the error messagenode- theASTNodewhere the error occurred
-
SyntaxException
Constructs a SyntaxException with line and column information. The end position defaults to one column after the start position.- Parameters:
message- the error messagestartLine- the line number where the error starts (1-based)startColumn- the column number where the error starts (1-based)
-
SyntaxException
Constructs a SyntaxException with complete position range information.- Parameters:
message- the error messagestartLine- the line number where the error starts (1-based)startColumn- the column number where the error starts (1-based)endLine- the line number where the error ends (1-based)endColumn- the column number where the error ends (1-based)
-
SyntaxException
Constructs a SyntaxException with a cause exception. The end position defaults to one column after the start position.- Parameters:
message- the error messagecause- the underlyingThrowablethat caused this exceptionstartLine- the line number where the error starts (1-based)startColumn- the column number where the error starts (1-based)
-
SyntaxException
public SyntaxException(String message, Throwable cause, int startLine, int startColumn, int endLine, int endColumn) Constructs a SyntaxException with a cause exception and complete position information.- Parameters:
message- the error messagecause- the underlyingThrowablethat caused this exceptionstartLine- the line number where the error starts (1-based)startColumn- the column number where the error starts (1-based)endLine- the line number where the error ends (1-based)endColumn- the column number where the error ends (1-based)
-
-
Method Details
-
setSourceLocator
Sets an optional source locator string (e.g., file path, URL).- Parameters:
sourceLocator- the source location identifier
-
getSourceLocator
Returns the optional source locator string.- Returns:
- the source location identifier, or
nullif not set
-
getLine
public int getLine()Returns the starting line number of the error. Provided for backward compatibility; equivalent togetStartLine().- Returns:
- the line number (1-based)
-
getStartLine
public int getStartLine()Returns the starting line number of the error.- Returns:
- the line number (1-based)
-
getStartColumn
public int getStartColumn()Returns the starting column number of the error.- Returns:
- the column number (1-based)
-
getEndLine
public int getEndLine()Returns the ending line number of the error.- Returns:
- the line number (1-based)
-
getEndColumn
public int getEndColumn()Returns the ending column number of the error.- Returns:
- the column number (1-based)
-
getOriginalMessage
Returns the original error message without location information.- Returns:
- the base error message
-
getMessage
Returns the error message with location information appended.- Overrides:
getMessagein classThrowable- Returns:
- the formatted message including line and column information
-