Class OpenIllegalStateException
- All Implemented Interfaces:
OpenExceptionMeta, Serializable
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 Summary
ConstructorsConstructorDescriptionOpenIllegalStateException(String message) Creates 创建状态异常OpenIllegalStateException(String message, Throwable cause) Creates 创建状态异常(带原因) -
Method Summary
Modifier and TypeMethodDescriptionstatic OpenIllegalStateExceptionalreadyClosed(String resourceName) Creates 创建"已关闭"异常static OpenIllegalStateExceptionalreadyExists(String itemName, Object key) Creates 创建"已存在"异常Gets the component name 获取组件名称Gets the error code 获取错误码static OpenIllegalStateExceptioninvalidState(String expected, String actual) Creates 创建"无效状态"异常static OpenIllegalStateExceptionCreates 创建"未找到"异常static OpenIllegalStateExceptionnotInitialized(String componentName) Creates 创建"未初始化"异常Methods inherited from class Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, 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
-
OpenIllegalStateException
Creates 创建状态异常- Parameters:
message- the value | 异常消息
-
OpenIllegalStateException
-
-
Method Details
-
getErrorCode
Gets the error code 获取错误码- Specified by:
getErrorCodein interfaceOpenExceptionMeta- Returns:
- the error code | 错误码
-
getComponent
Gets the component name 获取组件名称- Specified by:
getComponentin interfaceOpenExceptionMeta- Returns:
- the component name | 组件名称
-
notInitialized
Creates 创建"未初始化"异常- Parameters:
componentName- the value | 组件名- Returns:
- the result | 异常实例
-
alreadyClosed
Creates 创建"已关闭"异常- Parameters:
resourceName- the value | 资源名- Returns:
- the result | 异常实例
-
alreadyExists
Creates 创建"已存在"异常- Parameters:
itemName- the value | 项目名key- the key | 键- Returns:
- the result | 异常实例
-
notFound
Creates 创建"未找到"异常- Parameters:
itemName- the value | 项目名key- the key | 键- Returns:
- the result | 异常实例
-
invalidState
Creates 创建"无效状态"异常- Parameters:
expected- the value | 期望状态actual- the value | 实际状态- Returns:
- the result | 异常实例
-