package com.flowable.devops.expression;

/**
 * 表达式解析异常
 * 
 * 在表达式解析或执行过程中出现错误时抛出
 */
public class ExpressionEvaluationException extends RuntimeException {

    private final String expression;

    public ExpressionEvaluationException(String message) {
        super(message);
        this.expression = null;
    }

    public ExpressionEvaluationException(String message, Throwable cause) {
        super(message, cause);
        this.expression = null;
    }

    public ExpressionEvaluationException(String message, String expression) {
        super(message);
        this.expression = expression;
    }

    public ExpressionEvaluationException(String message, String expression, Throwable cause) {
        super(message, cause);
        this.expression = expression;
    }

    /**
     * 获取导致异常的表达式
     */
    public String getExpression() {
        return expression;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(getClass().getSimpleName()).append(": ").append(getMessage());
        if (expression != null) {
            sb.append(" [expression=").append(expression).append("]");
        }
        return sb.toString();
    }
}