IllegalArgumentException

The standard unchecked exception for a method argument that is not acceptable, such as a blank identifier or a negative count.

In more detail

Throwing it in a record's compact constructor rejects invalid data at the boundary, so later code can trust the object. At the web boundary it usually becomes a 400 bad request response.

Example

throw new IllegalArgumentException("count cannot be negative");

Related terms

Taught in

References

Certification courses