IllegalArgumentException:Java 中常见的运行时异常(RuntimeException 的子类),表示方法接收到不合法或不合适的参数(例如参数为负数、超出范围、格式不符合要求、与业务约束冲突等)。通常用于提示“调用方传参错误”。
/ɪˌliːɡəl ˈɑːrɡjʊmənt ɪkˈsɛpʃən/
Pass a negative size and the method will throw an IllegalArgumentException.
传入负数的大小参数时,该方法会抛出 IllegalArgumentException。
To protect invariants, the constructor validates inputs and throws IllegalArgumentException when the string is null or its length exceeds the limit.
为保证不变量,构造函数会校验输入;当字符串为 null 或长度超过限制时将抛出 IllegalArgumentException。
该词由三部分构成:illegal(非法的/不符合规则的)+ argument(参数)+ exception(异常)。在 Java 命名习惯中以 CamelCase 形式出现,用来直观表达“由于参数不合法而产生的异常”。它是 Java 标准库中用于参数校验的经典异常类型之一。
IllegalArgumentException 等异常类型。