Class OpenDateException

All Implemented Interfaces:
OpenExceptionMeta, Serializable

public class OpenDateException extends OpenException
Date Exception Class for OpenCode Date Module OpenCode日期模块异常类

This exception is thrown when date/time operations fail, including:

当日期时间操作失败时抛出此异常,包括:

Features | 主要功能:

  • Parse failures - 解析失败
  • Format failures - 格式化失败
  • Invalid date/time values - 无效的日期时间值
  • Timezone conversion errors - 时区转换错误
  • Range validation failures - 范围验证失败

Usage Examples | 使用示例:

// Throwing parse exception
throw OpenDateException.parseError("2024-13-45", "Invalid date format");

// Throwing format exception
throw OpenDateException.formatError("Failed to format date");

// Throwing with cause
throw new OpenDateException("Operation failed", cause);

Security | 安全性:

  • Thread-safe: Yes - 线程安全: 是
  • Immutable: Yes - 不可变: 是
Since:
JDK 25, opencode-base-date V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • OpenDateException

      public OpenDateException(String message)
      Constructs an exception with a message 使用消息构造异常
      Parameters:
      message - the detail message | 详细消息
    • OpenDateException

      public OpenDateException(String message, Throwable cause)
      Constructs an exception with a message and cause 使用消息和原因构造异常
      Parameters:
      message - the detail message | 详细消息
      cause - the cause | 原因
    • OpenDateException

      public OpenDateException(String message, String inputValue, String expectedFormat)
      Constructs an exception with all details 使用所有详细信息构造异常
      Parameters:
      message - the detail message | 详细消息
      inputValue - the input value that caused the error | 导致错误的输入值
      expectedFormat - the expected format | 期望的格式
    • OpenDateException

      public OpenDateException(String message, String inputValue, String expectedFormat, Throwable cause)
      Constructs an exception with all details and cause 使用所有详细信息和原因构造异常
      Parameters:
      message - the detail message | 详细消息
      inputValue - the input value that caused the error | 导致错误的输入值
      expectedFormat - the expected format | 期望的格式
      cause - the cause | 原因
  • Method Details

    • parseError

      public static OpenDateException parseError(String input, String pattern)
      Creates a parse error exception 创建解析错误异常
      Parameters:
      input - the input that failed to parse | 解析失败的输入
      pattern - the expected pattern | 期望的模式
      Returns:
      the exception instance | 异常实例
    • parseError

      public static OpenDateException parseError(String input, String pattern, Throwable cause)
      Creates a parse error exception with cause 创建带原因的解析错误异常
      Parameters:
      input - the input that failed to parse | 解析失败的输入
      pattern - the expected pattern | 期望的模式
      cause - the cause | 原因
      Returns:
      the exception instance | 异常实例
    • parseError

      public static OpenDateException parseError(String input)
      Creates a parse error exception for smart parsing 创建智能解析的解析错误异常
      Parameters:
      input - the input that failed to parse | 解析失败的输入
      Returns:
      the exception instance | 异常实例
    • formatError

      public static OpenDateException formatError(String message)
      Creates a format error exception 创建格式化错误异常
      Parameters:
      message - the error message | 错误消息
      Returns:
      the exception instance | 异常实例
    • formatError

      public static OpenDateException formatError(String message, Throwable cause)
      Creates a format error exception with cause 创建带原因的格式化错误异常
      Parameters:
      message - the error message | 错误消息
      cause - the cause | 原因
      Returns:
      the exception instance | 异常实例
    • invalidValue

      public static OpenDateException invalidValue(String field, Object value, String range)
      Creates an invalid value exception 创建无效值异常
      Parameters:
      field - the field name | 字段名
      value - the invalid value | 无效值
      range - the valid range description | 有效范围描述
      Returns:
      the exception instance | 异常实例
    • timezoneError

      public static OpenDateException timezoneError(String zoneId)
      Creates a timezone error exception 创建时区错误异常
      Parameters:
      zoneId - the invalid zone ID | 无效的时区ID
      Returns:
      the exception instance | 异常实例
    • rangeError

      public static OpenDateException rangeError(String message)
      Creates a range error exception 创建范围错误异常
      Parameters:
      message - the error message | 错误消息
      Returns:
      the exception instance | 异常实例
    • cronError

      public static OpenDateException cronError(String expression, String reason)
      Creates a cron expression error 创建Cron表达式错误异常
      Parameters:
      expression - the invalid cron expression | 无效的Cron表达式
      reason - the reason | 原因
      Returns:
      the exception instance | 异常实例
    • cronError

      public static OpenDateException cronError(String expression, String reason, Throwable cause)
      Creates a cron expression error with cause 创建带原因的Cron表达式错误异常
      Parameters:
      expression - the invalid cron expression | 无效的Cron表达式
      reason - the reason | 原因
      cause - the cause | 原因
      Returns:
      the exception instance | 异常实例
    • getInputValue

      public String getInputValue()
      Gets the input value that caused the exception 获取导致异常的输入值
      Returns:
      the input value, or null if not available | 输入值,如果不可用则为null
    • getExpectedFormat

      public String getExpectedFormat()
      Gets the expected format 获取期望的格式
      Returns:
      the expected format, or null if not available | 期望的格式,如果不可用则为null
    • hasInputValue

      public boolean hasInputValue()
      Checks if input value is available 检查输入值是否可用
      Returns:
      true if input value is available | 如果输入值可用则返回true
    • hasExpectedFormat

      public boolean hasExpectedFormat()
      Checks if expected format is available 检查期望格式是否可用
      Returns:
      true if expected format is available | 如果期望格式可用则返回true