Class OpenCronException

All Implemented Interfaces:
OpenExceptionMeta, Serializable

public class OpenCronException extends OpenException
Cron Exception - Exception for Cron Expression Errors Cron异常 - Cron表达式错误异常

Thrown when cron expression parsing, validation, or evaluation fails. Extends OpenException to maintain consistent exception hierarchy. Carries diagnostic context including the original expression and the problematic field name.

当Cron表达式解析、验证或计算失败时抛出。 继承 OpenException 以保持一致的异常体系。 携带诊断上下文,包括原始表达式和有问题的字段名称。

Features | 主要功能:

  • Extends OpenException for unified hierarchy - 继承OpenException统一异常体系
  • Diagnostic fields: expression, field name - 诊断字段:表达式、字段名称
  • Factory methods for common error types - 常见错误类型的工厂方法
  • Serializable - 可序列化

Usage Examples | 使用示例:

throw OpenCronException.parseError("invalid", "expected 5 or 6 fields");
throw OpenCronException.fieldError("hour", 25, 0, 23);

Security | 安全性:

  • Thread-safe: Yes (immutable exception) - 线程安全: 是(不可变异常)
  • Null-safe: No - 空值安全: 否
Since:
JDK 25, opencode-base-cron V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • OpenCronException

      public OpenCronException(String message)
      Constructs exception with message 构造带消息的异常
      Parameters:
      message - the detail message | 详细消息
    • OpenCronException

      public OpenCronException(String message, Throwable cause)
      Constructs exception with message and cause 构造带消息和原因的异常
      Parameters:
      message - the detail message | 详细消息
      cause - the cause | 原因
    • OpenCronException

      public OpenCronException(String message, String expression, String field, Throwable cause)
      Constructs exception with all diagnostic fields 构造带所有诊断字段的异常
      Parameters:
      message - the detail message | 详细消息
      expression - the cron expression | Cron表达式
      field - the problematic field | 有问题的字段
      cause - the cause | 原因
  • Method Details

    • getExpression

      public String getExpression()
      Gets the cron expression that caused the error 获取导致错误的Cron表达式
      Returns:
      the expression, or null | 表达式,或null
    • getField

      public String getField()
      Gets the problematic field name 获取有问题的字段名称
      Returns:
      the field name, or null | 字段名称,或null
    • parseError

      public static OpenCronException parseError(String expression, String reason)
      Creates exception for parse errors 为解析错误创建异常
      Parameters:
      expression - the expression | 表达式
      reason - the reason | 原因
      Returns:
      the exception | 异常
    • parseError

      public static OpenCronException parseError(String expression, String reason, Throwable cause)
      Creates exception for parse errors with cause 为带原因的解析错误创建异常
      Parameters:
      expression - the expression | 表达式
      reason - the reason | 原因
      cause - the cause | 原因
      Returns:
      the exception | 异常
    • fieldError

      public static OpenCronException fieldError(String field, int value, int min, int max)
      Creates exception for invalid field values 为无效字段值创建异常
      Parameters:
      field - the field name | 字段名称
      value - the invalid value | 无效值
      min - the minimum allowed value | 允许的最小值
      max - the maximum allowed value | 允许的最大值
      Returns:
      the exception | 异常
    • fieldError

      public static OpenCronException fieldError(String field, String fieldValue, String reason)
      Creates exception for invalid field expression 为无效字段表达式创建异常
      Parameters:
      field - the field name | 字段名称
      fieldValue - the invalid field value | 无效字段值
      reason - the reason | 原因
      Returns:
      the exception | 异常
    • unknownMacro

      public static OpenCronException unknownMacro(String macro)
      Creates exception for unknown macro 为未知宏创建异常
      Parameters:
      macro - the unknown macro | 未知宏
      Returns:
      the exception | 异常