Class OpenIllegalArgumentException

All Implemented Interfaces:
OpenExceptionMeta, Serializable

public class OpenIllegalArgumentException extends IllegalArgumentException implements OpenExceptionMeta
Illegal Argument Exception - Parameter validation exception 参数校验异常 - 方法参数验证异常

Thrown when method arguments do not meet expected conditions. Extends IllegalArgumentException so it is catchable by standard JDK catch clauses, while also carrying component/errorCode metadata consistent with the OpenCode exception model.

当方法参数不满足预期条件时抛出此异常。继承 IllegalArgumentException, 既可被标准JDK catch子句捕获,又携带与OpenCode异常模型一致的组件/错误码元数据。

Features | 主要功能:

  • Not null check (notNull) - 非空检查
  • Not empty check (notEmpty) - 非空字符串检查
  • Not blank check (notBlank) - 非空白检查
  • Range validation (positive, nonNegative, outOfRange) - 范围验证
  • Index bounds check (indexOutOfBounds) - 索引边界检查

Usage Examples | 使用示例:

if (name == null || name.isEmpty()) {
    throw new OpenIllegalArgumentException("name must not be empty");
}

// Static factory methods - 静态工厂方法
throw OpenIllegalArgumentException.notNull("userId");
throw OpenIllegalArgumentException.notEmpty("name");
throw OpenIllegalArgumentException.positive("count", -1);

Important | 重要说明: Note: This exception extends IllegalArgumentException (not OpenException) to maintain compatibility with standard JDK exception handling. Use catch(IllegalArgumentException e) or catch this class directly. catch(OpenException e) will NOT catch this exception.

注意:此异常继承自 IllegalArgumentException(而非 OpenException), 以保持与标准 JDK 异常处理的兼容性。请使用 catch(IllegalArgumentException 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 Details

    • OpenIllegalArgumentException

      public OpenIllegalArgumentException(String message)
      Creates 创建参数异常
      Parameters:
      message - the value | 异常消息
    • OpenIllegalArgumentException

      public OpenIllegalArgumentException(String message, Throwable cause)
      Creates 创建参数异常(带原因)
      Parameters:
      message - the value | 异常消息
      cause - the value | 原始异常
  • Method Details

    • getErrorCode

      public String getErrorCode()
      Gets the error code 获取错误码
      Specified by:
      getErrorCode in interface OpenExceptionMeta
      Returns:
      the error code | 错误码
    • getComponent

      public String getComponent()
      Gets the component name 获取组件名称
      Specified by:
      getComponent in interface OpenExceptionMeta
      Returns:
      the component name | 组件名称
    • notNull

      public static OpenIllegalArgumentException notNull(String paramName)
      Creates 创建"参数不能为 null"异常
      Parameters:
      paramName - the value | 参数名
      Returns:
      the result | 异常实例
    • notEmpty

      public static OpenIllegalArgumentException notEmpty(String paramName)
      Creates 创建"参数不能为空"异常
      Parameters:
      paramName - the value | 参数名
      Returns:
      the result | 异常实例
    • notBlank

      public static OpenIllegalArgumentException notBlank(String paramName)
      Creates 创建"参数不能为空白"异常
      Parameters:
      paramName - the value | 参数名
      Returns:
      the result | 异常实例
    • positive

      public static OpenIllegalArgumentException positive(String paramName, Number value)
      Creates 创建"参数必须为正数"异常
      Parameters:
      paramName - the value | 参数名
      value - the value | 实际值
      Returns:
      the result | 异常实例
    • nonNegative

      public static OpenIllegalArgumentException nonNegative(String paramName, Number value)
      Creates 创建"参数必须为非负数"异常
      Parameters:
      paramName - the value | 参数名
      value - the value | 实际值
      Returns:
      the result | 异常实例
    • outOfRange

      public static OpenIllegalArgumentException outOfRange(String paramName, Number value, Number min, Number max)
      Creates 创建"参数超出范围"异常
      Parameters:
      paramName - the value | 参数名
      value - the value | 实际值
      min - the value | 最小值
      max - the value | 最大值
      Returns:
      the result | 异常实例
    • indexOutOfBounds

      public static OpenIllegalArgumentException indexOutOfBounds(int index, int size)
      Creates 创建"索引超出范围"异常
      Parameters:
      index - the value | 索引值
      size - the value | 集合大小
      Returns:
      the result | 异常实例