Class YmlPathException

All Implemented Interfaces:
OpenExceptionMeta, Serializable

public class YmlPathException extends OpenYmlException
YAML Path Exception - Thrown when path access fails YAML 路径异常 - 当路径访问失败时抛出

This exception is thrown when a path does not exist or is invalid.

当路径不存在或无效时抛出此异常。

Features | 主要功能:

  • Tracks the failing path for diagnostics - 跟踪失败路径以供诊断
  • Factory methods for index-out-of-bounds and type-mismatch errors - 索引越界和类型不匹配错误的工厂方法
  • Error code YML_PATH_001 - 错误码 YML_PATH_001

Usage Examples | 使用示例:

try {
    String value = PathResolver.get(data, "missing.path");
} catch (YmlPathException e) {
    System.err.println("Path not found: " + e.getPath());
}

Security | 安全性:

  • Thread-safe: Yes (immutable after construction) - 线程安全: 是(构建后不可变)
  • Null-safe: No (path may be null) - 空值安全: 否(路径可能为空)
Since:
JDK 25, opencode-base-yml V1.0.3
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • YmlPathException

      public YmlPathException(String path)
      Constructs a path exception for missing path. 为缺失路径构造路径异常。
      Parameters:
      path - the missing path | 缺失的路径
    • YmlPathException

      public YmlPathException(String path, String message)
      Constructs a path exception with message. 构造带消息的路径异常。
      Parameters:
      path - the path | 路径
      message - the detail message | 详细消息
    • YmlPathException

      public YmlPathException(String path, String message, Throwable cause)
      Constructs a path exception with message and cause. 构造带消息和原因的路径异常。
      Parameters:
      path - the path | 路径
      message - the detail message | 详细消息
      cause - the cause | 原因
  • Method Details

    • getPath

      public String getPath()
      Gets the path that caused the exception. 获取导致异常的路径。
      Returns:
      the path | 路径
    • indexOutOfBounds

      public static YmlPathException indexOutOfBounds(String path, int index, int size)
      Creates an exception for index out of bounds. 为索引越界创建异常。
      Parameters:
      path - the path | 路径
      index - the index | 索引
      size - the sequence size | 序列大小
      Returns:
      the exception | 异常
    • typeMismatch

      public static YmlPathException typeMismatch(String path, String expected, String actual)
      Creates an exception for type mismatch. 为类型不匹配创建异常。
      Parameters:
      path - the path | 路径
      expected - the expected type | 期望类型
      actual - the actual type | 实际类型
      Returns:
      the exception | 异常