Class OpenIllegalStateException

All Implemented Interfaces:
OpenExceptionMeta, Serializable

public class OpenIllegalStateException extends IllegalStateException implements OpenExceptionMeta
Illegal State Exception - Object state validation exception 状态异常 - 对象状态验证异常

Thrown when object state does not meet operation preconditions. Extends IllegalStateException so it is catchable by standard JDK catch clauses, while also carrying component/errorCode metadata consistent with the OpenCode exception model.

当对象状态不满足操作的前置条件时抛出此异常。继承 IllegalStateException, 既可被标准JDK catch子句捕获,又携带与OpenCode异常模型一致的组件/错误码元数据。

Features | 主要功能:

  • Not initialized check (notInitialized) - 未初始化检查
  • Already closed check (alreadyClosed) - 已关闭检查
  • Already exists check (alreadyExists) - 已存在检查
  • Not found check (notFound) - 未找到检查
  • Invalid state check (invalidState) - 无效状态检查

Usage Examples | 使用示例:

if (!initialized) {
    throw new OpenIllegalStateException("Component not initialized");
}

// Static factory methods - 静态工厂方法
throw OpenIllegalStateException.notInitialized("CacheManager");
throw OpenIllegalStateException.alreadyClosed("Connection");
throw OpenIllegalStateException.notFound("User", userId);

Important | 重要说明: Note: This exception extends IllegalStateException (not OpenException) to maintain compatibility with standard JDK exception handling. Use catch(IllegalStateException e) or catch this class directly. catch(OpenException e) will NOT catch this exception.

注意:此异常继承自 IllegalStateException(而非 OpenException), 以保持与标准 JDK 异常处理的兼容性。请使用 catch(IllegalStateException e) 或直接捕获此类。 catch(OpenException e) 无法捕获此异常。

Security | 安全性:

  • Thread-safe: Yes (immutable) - 线程安全: 是 (不可变)
  • Serializable: Yes - 可序列化: 是
Since:
JDK 25, opencode-base-core V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • OpenIllegalStateException

      public OpenIllegalStateException(String message)
      Creates 创建状态异常
      Parameters:
      message - the value | 异常消息
    • OpenIllegalStateException

      public OpenIllegalStateException(String message, Throwable cause)
      Creates 创建状态异常(带原因)
      Parameters:
      message - the value | 异常消息
      cause - the value | 原始异常
  • Method Details

    • getErrorCode

      public String getErrorCode()
      Gets the error code 获取错误码
      Specified by:
      getErrorCode in interface OpenExceptionMeta
      Returns:
      the error code | 错误码
    • getComponent

      public String getComponent()
      Gets the component name 获取组件名称
      Specified by:
      getComponent in interface OpenExceptionMeta
      Returns:
      the component name | 组件名称
    • notInitialized

      public static OpenIllegalStateException notInitialized(String componentName)
      Creates 创建"未初始化"异常
      Parameters:
      componentName - the value | 组件名
      Returns:
      the result | 异常实例
    • alreadyClosed

      public static OpenIllegalStateException alreadyClosed(String resourceName)
      Creates 创建"已关闭"异常
      Parameters:
      resourceName - the value | 资源名
      Returns:
      the result | 异常实例
    • alreadyExists

      public static OpenIllegalStateException alreadyExists(String itemName, Object key)
      Creates 创建"已存在"异常
      Parameters:
      itemName - the value | 项目名
      key - the key | 键
      Returns:
      the result | 异常实例
    • notFound

      public static OpenIllegalStateException notFound(String itemName, Object key)
      Creates 创建"未找到"异常
      Parameters:
      itemName - the value | 项目名
      key - the key | 键
      Returns:
      the result | 异常实例
    • invalidState

      public static OpenIllegalStateException invalidState(String expected, String actual)
      Creates 创建"无效状态"异常
      Parameters:
      expected - the value | 期望状态
      actual - the value | 实际状态
      Returns:
      the result | 异常实例