Class TreeException

All Implemented Interfaces:
OpenExceptionMeta, Serializable
Direct Known Subclasses:
CycleDetectedException

public class TreeException extends OpenException
Tree Exception - Base exception for tree operations 树异常 - 树操作的基础异常

Extends OpenException to integrate with the unified OpenCode exception hierarchy.

继承 OpenException 以集成统一的 OpenCode 异常体系。

Features | 主要功能:

  • Base exception for tree operations - 树操作的基础异常
  • Error code support via TreeErrorCode - 通过 TreeErrorCode 支持错误码
  • Factory methods for common errors - 常见错误的工厂方法
  • Integrates with OpenException (component="Tree") - 集成 OpenException(组件="Tree")

Usage Examples | 使用示例:

throw TreeException.duplicateId(nodeId);
throw TreeException.nodeNotFound(nodeId);
throw TreeException.maxDepthExceeded(1000);

Security | 安全性:

  • Thread-safe: Yes (immutable after construction) - 是(构造后不可变)
  • Null-safe: No (message should not be null) - 否(消息不应为null)
Since:
JDK 25, opencode-base-tree V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • TreeException

      public TreeException(String message)
      Creates a tree exception with message 创建树异常(带消息)
      Parameters:
      message - the error message | 错误消息
    • TreeException

      public TreeException(String code, String message)
      Creates a tree exception with code and message 创建树异常(带错误码和消息)
      Parameters:
      code - the error code | 错误码
      message - the error message | 错误消息
    • TreeException

      public TreeException(TreeErrorCode errorCode)
      Creates a tree exception with error code enum 创建树异常(带错误码枚举)
      Parameters:
      errorCode - the error code enum | 错误码枚举
    • TreeException

      public TreeException(TreeErrorCode errorCode, String message)
      Creates a tree exception with error code enum and custom message 创建树异常(带错误码枚举和自定义消息)
      Parameters:
      errorCode - the error code enum | 错误码枚举
      message - the custom message | 自定义消息
    • TreeException

      public TreeException(String message, Throwable cause)
      Creates a tree exception with message and cause 创建树异常(带消息和原因)
      Parameters:
      message - the error message | 错误消息
      cause - the cause | 原因
    • TreeException

      public TreeException(TreeErrorCode errorCode, Throwable cause)
      Creates a tree exception with error code enum and cause 创建树异常(带错误码枚举和原因)
      Parameters:
      errorCode - the error code enum | 错误码枚举
      cause - the cause | 原因
  • Method Details

    • getCode

      public String getCode()
      Gets the tree-specific error code 获取树特定的错误码
      Returns:
      the error code string | 错误码字符串
    • buildFailed

      public static TreeException buildFailed(String message)
      Creates a build-failed exception 创建构建失败异常
      Parameters:
      message - the error message | 错误消息
      Returns:
      the exception | 异常
    • invalidNode

      public static TreeException invalidNode(String message)
      Creates an invalid-node exception 创建无效节点异常
      Parameters:
      message - the error message | 错误消息
      Returns:
      the exception | 异常
    • duplicateId

      public static TreeException duplicateId(Object id)
      Creates a duplicate-id exception 创建重复ID异常
      Parameters:
      id - the duplicate ID | 重复的ID
      Returns:
      the exception | 异常
    • parentNotFound

      public static TreeException parentNotFound(Object parentId)
      Creates a parent-not-found exception 创建父节点未找到异常
      Parameters:
      parentId - the parent ID | 父节点ID
      Returns:
      the exception | 异常
    • nodeNotFound

      public static TreeException nodeNotFound(Object id)
      Creates a node-not-found exception 创建节点未找到异常
      Parameters:
      id - the node ID | 节点ID
      Returns:
      the exception | 异常
    • maxDepthExceeded

      public static TreeException maxDepthExceeded(int maxDepth)
      Creates a max-depth-exceeded exception 创建超过最大深度异常
      Parameters:
      maxDepth - the max depth | 最大深度
      Returns:
      the exception | 异常