Interface OpenExceptionMeta

All Known Implementing Classes:
OpenException, OpenIllegalArgumentException, OpenIllegalStateException, OpenIOException, OpenTimeoutException, OpenUnsupportedOperationException

public interface OpenExceptionMeta
Shared metadata interface for all Open* exceptions. 所有 Open* 异常的共用元数据接口。

Implemented by OpenException (and therefore all its subclasses), as well as by Open* variants that extend a JDK-native exception for idiom compatibility (e.g. OpenIllegalArgumentException extends IllegalArgumentException, OpenUnsupportedOperationException extends UnsupportedOperationException). A single instanceof check therefore gives uniform metadata access across both inheritance branches:

try {
    op();
} catch (Exception ex) {
    if (ex instanceof OpenExceptionMeta meta) {
        log.error("[{}] ({}) {}",
                meta.getComponent(), meta.getErrorCode(), ex.getMessage());
    }
    throw ex;
}

实现方包括 OpenException(及其所有子类),以及那些为和 JDK 习惯 对齐而直接继承 JDK 原生异常的 Open* 变种(如 OpenIllegalArgumentException 继承 IllegalArgumentExceptionOpenUnsupportedOperationException 继承 UnsupportedOperationException)。通过一次 instanceof 即可 跨两条继承链统一访问 metadata。

Since:
JDK 25, opencode-base-core V1.0.4
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    Component name identifying the logical source of the exception.
    Stable machine-readable error code.
    default String
    Convenience formatter combining component and error code.
  • Method Details

    • getComponent

      String getComponent()
      Component name identifying the logical source of the exception. 组件名,标识异常的逻辑归属。
      Returns:
      the component name | 组件名
    • getErrorCode

      String getErrorCode()
      Stable machine-readable error code. 稳定的机器可读错误码。
      Returns:
      the error code | 错误码
    • getMetaPrefix

      default String getMetaPrefix()
      Convenience formatter combining component and error code. 便捷格式化,拼接组件名与错误码。
      Returns:
      "[{component}] ({errorCode})" prefix | "[{组件}] ({错误码})" 前缀