Class ParserException
java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
cloud.opencode.base.core.exception.OpenException
cloud.opencode.base.expression.OpenExpressionException
cloud.opencode.base.expression.parser.ParserException
- All Implemented Interfaces:
OpenExceptionMeta, Serializable
Parser Exception
解析异常
Thrown when an error occurs during expression parsing. Includes detailed position information for error reporting.
在表达式解析过程中发生错误时抛出。包含用于错误报告的详细位置信息。
Features | 主要功能:
- Detailed error position (line, column) - 详细的错误位置(行、列)
- Expression context with position indicator (^) - 表达式上下文和位置指示符
- Typed error categories via ErrorType enum - 通过ErrorType枚举的类型化错误分类
- Static factory methods for common parse errors - 常见解析错误的静态工厂方法
Usage Examples | 使用示例:
try {
Parser.parse("1 ++ 2");
} catch (ParserException e) {
int line = e.getLine();
int col = e.getColumn();
ParserException.ErrorType type = e.getErrorType();
}
// Create specific errors
throw ParserException.unexpectedToken("+", "1 ++ 2", 3);
throw ParserException.unterminatedString(5);
Security | 安全性:
- Thread-safe: Yes, immutable after construction - 线程安全: 是,构造后不可变
- Null-safe: Yes, null expression handled in formatting - 空值安全: 是,null表达式在格式化中处理
- Since:
- JDK 25, opencode-base-expression V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionParserException(String message) Create parser exception 创建解析异常ParserException(String message, int position) Create parser exception with position 创建带位置的解析异常ParserException(String message, String expression, int position) Create parser exception with expression and position 创建带表达式和位置的解析异常ParserException(String message, String expression, int line, int column, ParserException.ErrorType errorType) Create parser exception with full details 创建带完整详情的解析异常 -
Method Summary
Modifier and TypeMethodDescriptionstatic ParserExceptionexpectedToken(String expected, String actual, int position) Create expected token error 创建期望词法单元错误static ParserExceptionexpectedToken(String expected, String actual, String expression, int position) Create expected token error with expression 创建带表达式的期望词法单元错误intGet the column number 获取列号Get the error type 获取错误类型Get the expression 获取表达式intgetLine()Get the line number 获取行号static ParserExceptioninvalidEscapeSequence(String sequence, int position) Create invalid escape sequence error 创建无效转义序列错误static ParserExceptioninvalidNumber(String value, int position) Create invalid number format error 创建无效数字格式错误static ParserExceptionunbalancedParentheses(int position) Create unbalanced parentheses error 创建不平衡括号错误static ParserExceptionunexpectedEnd(String expression) Create unexpected end of expression error 创建表达式意外结束错误static ParserExceptionunexpectedToken(String token, int position) Create unexpected token error 创建意外词法单元错误static ParserExceptionunexpectedToken(String token, String expression, int position) Create unexpected token error with expression 创建带表达式的意外词法单元错误static ParserExceptionunterminatedString(int position) Create unterminated string error 创建未终止字符串错误Methods inherited from class OpenExpressionException
divisionByZero, evaluationError, evaluationError, functionNotFound, getPosition, methodNotFound, nullPointer, parseError, parseError, propertyNotFound, securityViolation, timeout, typeErrorMethods inherited from class OpenException
getComponent, getErrorCode, getMessage, getRawMessageMethods inherited from class Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toStringMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface OpenExceptionMeta
getMetaPrefix
-
Constructor Details
-
ParserException
Create parser exception 创建解析异常- Parameters:
message- the error message | 错误消息
-
ParserException
Create parser exception with position 创建带位置的解析异常- Parameters:
message- the error message | 错误消息position- the error position | 错误位置
-
ParserException
-
ParserException
public ParserException(String message, String expression, int line, int column, ParserException.ErrorType errorType) Create parser exception with full details 创建带完整详情的解析异常- Parameters:
message- the error message | 错误消息expression- the expression | 表达式line- the line number | 行号column- the column number | 列号errorType- the error type | 错误类型
-
-
Method Details
-
getExpression
Get the expression 获取表达式- Overrides:
getExpressionin classOpenExpressionException- Returns:
- the expression | 表达式
-
getLine
public int getLine()Get the line number 获取行号- Returns:
- the line number | 行号
-
getColumn
public int getColumn()Get the column number 获取列号- Returns:
- the column number | 列号
-
getErrorType
Get the error type 获取错误类型- Returns:
- the error type | 错误类型
-
unexpectedToken
Create unexpected token error 创建意外词法单元错误- Parameters:
token- the unexpected token | 意外的词法单元position- the position | 位置- Returns:
- the exception | 异常
-
unexpectedToken
Create unexpected token error with expression 创建带表达式的意外词法单元错误- Parameters:
token- the unexpected token | 意外的词法单元expression- the expression | 表达式position- the position | 位置- Returns:
- the exception | 异常
-
expectedToken
Create expected token error 创建期望词法单元错误- Parameters:
expected- the expected token | 期望的词法单元actual- the actual token | 实际的词法单元position- the position | 位置- Returns:
- the exception | 异常
-
expectedToken
public static ParserException expectedToken(String expected, String actual, String expression, int position) Create expected token error with expression 创建带表达式的期望词法单元错误- Parameters:
expected- the expected token | 期望的词法单元actual- the actual token | 实际的词法单元expression- the expression | 表达式position- the position | 位置- Returns:
- the exception | 异常
-
unexpectedEnd
Create unexpected end of expression error 创建表达式意外结束错误- Parameters:
expression- the expression | 表达式- Returns:
- the exception | 异常
-
invalidNumber
Create invalid number format error 创建无效数字格式错误- Parameters:
value- the invalid value | 无效的值position- the position | 位置- Returns:
- the exception | 异常
-
unterminatedString
Create unterminated string error 创建未终止字符串错误- Parameters:
position- the position | 位置- Returns:
- the exception | 异常
-
invalidEscapeSequence
Create invalid escape sequence error 创建无效转义序列错误- Parameters:
sequence- the invalid sequence | 无效的序列position- the position | 位置- Returns:
- the exception | 异常
-
unbalancedParentheses
Create unbalanced parentheses error 创建不平衡括号错误- Parameters:
position- the position | 位置- Returns:
- the exception | 异常
-