Class OpenIllegalArgumentException
java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
cloud.opencode.base.core.exception.OpenException
cloud.opencode.base.core.exception.OpenIllegalArgumentException
- All Implemented Interfaces:
Serializable
Illegal Argument Exception - Parameter validation exception
参数校验异常 - 方法参数验证异常
Thrown when method arguments do not meet expected conditions. Replaces IllegalArgumentException.
当方法参数不满足预期条件时抛出此异常。替代 IllegalArgumentException,提供统一的异常处理。
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);
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 TypeMethodDescriptionstatic 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 OpenException
getComponent, getErrorCode, getMessage, getRawMessageMethods inherited from class Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Constructor Details
-
OpenIllegalArgumentException
Creates 创建参数异常- Parameters:
message- the value | 异常消息
-
OpenIllegalArgumentException
-
-
Method Details
-
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 | 异常实例
-