Class OpenException
- All Implemented Interfaces:
OpenExceptionMeta, Serializable
- Direct Known Subclasses:
OpenIOException, OpenTimeoutException
Base exception for all OpenCode components with error code and component name support.
所有组件异常都应继承此类,支持错误码和组件名称,便于异常分类和定位。
Naming convention / 命名约定:
When an Open*Exception is conceptually "an upgraded drop-in replacement"
for a specific JDK-native exception, it MUST extend that
JDK-native type (not OpenException), keeping JDK idioms working
(catch, instanceof, AssertJ isInstanceOf). The
trade-off — catch (OpenException e) no longer catches these
variants — is intentional; use OpenExceptionMeta for unified
metadata access across both branches (see OpenExceptionMeta Javadoc).
当 Open*Exception 在语义上是某个 JDK 原生异常的"增强替代"时,
它必须继承对应 JDK 原生类(而非 OpenException),
保持 JDK 习惯(catch、instanceof、AssertJ
isInstanceOf)依然生效。代价是 catch (OpenException e)
无法捕获这些变种——这是刻意为之;如需跨两条继承链统一访问
metadata,请使用 OpenExceptionMeta。
Alignment table / 对齐表:
OpenIllegalArgumentExceptionextendsIllegalArgumentExceptionOpenIllegalStateExceptionextendsIllegalStateExceptionOpenUnsupportedOperationExceptionextendsUnsupportedOperationExceptionOpenIOExceptionextends this class (intentionally unchecked — wraps checkedIOException)
Features | 主要功能:
- Error code support - 错误码支持
- Component name support - 组件名称支持
- Formatted message output [Component] (Code) Message - 格式化消息输出
- RuntimeException (unchecked) - 非受检异常
Usage Examples | 使用示例:
throw new OpenException("Operation failed");
throw new OpenException("Core", "CORE_001", "Parameter required");
throw new OpenException("IO failed", cause);
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
ConstructorsConstructorDescriptionOpenException(String message) Creates 创建异常OpenException(String component, String errorCode, String message) Creates 创建异常(带组件和错误码)OpenException(String component, String errorCode, String message, Throwable cause) Creates 创建异常(完整参数)OpenException(String message, Throwable cause) Creates 创建异常(带原因) -
Method Summary
Modifier and TypeMethodDescriptionGets 获取组件名称Gets 获取错误码Gets 获取格式化的异常消息Gets 获取原始消息(不含组件和错误码前缀)Methods inherited from class Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, 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
-
OpenException
-
OpenException
-
OpenException
-
OpenException
-
-
Method Details
-
getErrorCode
Gets 获取错误码- Specified by:
getErrorCodein interfaceOpenExceptionMeta- Returns:
- the result | 错误码,可能为 null
-
getComponent
Gets 获取组件名称- Specified by:
getComponentin interfaceOpenExceptionMeta- Returns:
- the result | 组件名称,可能为 null
-
getRawMessage
-
getMessage
Gets 获取格式化的异常消息格式: [组件] (错误码) 消息
- Overrides:
getMessagein classThrowable- Returns:
- the result | 格式化的消息
-