Class OpenIllegalArgumentException
- All Implemented Interfaces:
OpenExceptionMeta, Serializable
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 Summary
ConstructorsConstructorDescriptionOpenIllegalArgumentException(String message) Creates 创建参数异常OpenIllegalArgumentException(String message, Throwable cause) Creates 创建参数异常(带原因) -
Method Summary
Modifier and TypeMethodDescriptionGets the component name 获取组件名称Gets the error code 获取错误码static OpenIllegalArgumentExceptionindexOutOfBounds(int index, int size) Creates 创建"索引超出范围"异常static OpenIllegalArgumentExceptionnonNegative(String paramName, Number value) Creates 创建"参数必须为非负数"异常static OpenIllegalArgumentExceptionCreates 创建"参数不能为空白"异常static OpenIllegalArgumentExceptionCreates 创建"参数不能为空"异常static OpenIllegalArgumentExceptionCreates 创建"参数不能为 null"异常static OpenIllegalArgumentExceptionoutOfRange(String paramName, Number value, Number min, Number max) Creates 创建"参数超出范围"异常static OpenIllegalArgumentExceptionCreates 创建"参数必须为正数"异常Methods inherited from class Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, 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
-
OpenIllegalArgumentException
Creates 创建参数异常- Parameters:
message- the value | 异常消息
-
OpenIllegalArgumentException
-
-
Method Details
-
getErrorCode
Gets the error code 获取错误码- Specified by:
getErrorCodein interfaceOpenExceptionMeta- Returns:
- the error code | 错误码
-
getComponent
Gets the component name 获取组件名称- Specified by:
getComponentin interfaceOpenExceptionMeta- Returns:
- the component name | 组件名称
-
notNull
Creates 创建"参数不能为 null"异常- Parameters:
paramName- the value | 参数名- Returns:
- the result | 异常实例
-
notEmpty
Creates 创建"参数不能为空"异常- Parameters:
paramName- the value | 参数名- Returns:
- the result | 异常实例
-
notBlank
Creates 创建"参数不能为空白"异常- Parameters:
paramName- the value | 参数名- Returns:
- the result | 异常实例
-
positive
Creates 创建"参数必须为正数"异常- Parameters:
paramName- the value | 参数名value- the value | 实际值- Returns:
- the result | 异常实例
-
nonNegative
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
Creates 创建"索引超出范围"异常- Parameters:
index- the value | 索引值size- the value | 集合大小- Returns:
- the result | 异常实例
-