Multiple choice technology programming languages

Which is the most appropriate way to handle invalid method arguments passed to a public method?

  1. Throw AssertionError

  2. Throw IllegalStateException

  3. Throw IllegalArgumentException

  4. Throw InvalidArgumentException

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

In Java, IllegalArgumentException is the standard runtime exception thrown to indicate that a method has been passed an illegal or inappropriate argument. AssertionError is for internal invariants, and IllegalStateException is for invalid object states.