Class OpenExpressionException
java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
cloud.opencode.base.core.exception.OpenException
cloud.opencode.base.expression.OpenExpressionException
- All Implemented Interfaces:
OpenExceptionMeta, Serializable
- Direct Known Subclasses:
ParserException, SandboxException
Expression Exception
表达式异常
Base exception for all expression-related errors including parsing, evaluation, type conversion, and security violations.
所有表达式相关错误的基础异常,包括解析、求值、类型转换和安全违规。
Features | 主要功能:
- Rich error context with expression string and position - 丰富的错误上下文,包含表达式字符串和位置
- Static factory methods for common error types - 常见错误类型的静态工厂方法
- Supports parse, evaluation, type, property, method, and security errors - 支持解析、求值、类型、属性、方法和安全错误
Usage Examples | 使用示例:
// Catch expression errors
try {
OpenExpression.eval("invalid ++ expr");
} catch (OpenExpressionException e) {
String expr = e.getExpression();
int pos = e.getPosition();
}
// Create specific error types
throw OpenExpressionException.parseError("Unexpected token", "1 ++ 2", 2);
throw OpenExpressionException.divisionByZero();
Security | 安全性:
- Thread-safe: Yes, immutable after construction - 线程安全: 是,构造后不可变
- Null-safe: Yes, null expression/position handled - 空值安全: 是,null表达式/位置已处理
- Since:
- JDK 25, opencode-base-expression V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionOpenExpressionException(String message) Create exception with message 创建带消息的异常OpenExpressionException(String message, String expression, int position) Create exception with expression context 创建带表达式上下文的异常OpenExpressionException(String message, Throwable cause) Create exception with message and cause 创建带消息和原因的异常 -
Method Summary
Modifier and TypeMethodDescriptionstatic OpenExpressionExceptionCreate division by zero error 创建除零错误static OpenExpressionExceptionevaluationError(String message) Create evaluation error 创建求值错误static OpenExpressionExceptionevaluationError(String message, Throwable cause) Create evaluation error 创建求值错误static OpenExpressionExceptionfunctionNotFound(String function) Create function not found error 创建函数未找到错误Get expression string 获取表达式字符串intGet error position 获取错误位置static OpenExpressionExceptionmethodNotFound(String method, Class<?> type) Create method not found error 创建方法未找到错误static OpenExpressionExceptionnullPointer(String context) Create null pointer error 创建空指针错误static OpenExpressionExceptionparseError(String message, int position) Create parse error with position only 创建只带位置的解析错误static OpenExpressionExceptionparseError(String message, String expression, int position) Create parse error 创建解析错误static OpenExpressionExceptionpropertyNotFound(String property, Class<?> type) Create property not found error 创建属性未找到错误static OpenExpressionExceptionsecurityViolation(String message) Create security violation error 创建安全违规错误static OpenExpressionExceptiontimeout(long millis) Create timeout error 创建超时错误static OpenExpressionExceptionCreate type error 创建类型错误Methods 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
-
OpenExpressionException
Create exception with message 创建带消息的异常- Parameters:
message- the error message | 错误消息
-
OpenExpressionException
-
OpenExpressionException
-
-
Method Details
-
getExpression
-
getPosition
public int getPosition()Get error position 获取错误位置- Returns:
- the position | 位置
-
parseError
Create parse error 创建解析错误- Parameters:
message- the error message | 错误消息expression- the expression | 表达式position- the position | 位置- Returns:
- the exception | 异常
-
parseError
Create parse error with position only 创建只带位置的解析错误- Parameters:
message- the error message | 错误消息position- the position | 位置- Returns:
- the exception | 异常
-
evaluationError
Create evaluation error 创建求值错误- Parameters:
message- the error message | 错误消息cause- the cause | 原因- Returns:
- the exception | 异常
-
evaluationError
Create evaluation error 创建求值错误- Parameters:
message- the error message | 错误消息- Returns:
- the exception | 异常
-
typeError
Create type error 创建类型错误- Parameters:
expected- the expected type | 期望类型actual- the actual value | 实际值- Returns:
- the exception | 异常
-
propertyNotFound
Create property not found error 创建属性未找到错误- Parameters:
property- the property name | 属性名type- the target type | 目标类型- Returns:
- the exception | 异常
-
methodNotFound
Create method not found error 创建方法未找到错误- Parameters:
method- the method name | 方法名type- the target type | 目标类型- Returns:
- the exception | 异常
-
functionNotFound
Create function not found error 创建函数未找到错误- Parameters:
function- the function name | 函数名- Returns:
- the exception | 异常
-
securityViolation
Create security violation error 创建安全违规错误- Parameters:
message- the error message | 错误消息- Returns:
- the exception | 异常
-
timeout
Create timeout error 创建超时错误- Parameters:
millis- the timeout in milliseconds | 超时毫秒数- Returns:
- the exception | 异常
-
divisionByZero
Create division by zero error 创建除零错误- Returns:
- the exception | 异常
-
nullPointer
Create null pointer error 创建空指针错误- Parameters:
context- the context description | 上下文描述- Returns:
- the exception | 异常
-