Java OCA OCP Practice Question 215

Question

How is IllegalArgumentException used?

Choose all correct options.

  • A. thrown by the JVM when a method is called with incompatible argument types.
  • B. thrown by the JVM to indicate arithmetic overflow.
  • C. thrown by certain methods of certain core Java classes to indicate that preconditions have been violated.
  • D. used by programmers to indicate that preconditions of public methods have been violated.
  • E. used by programmers to indicate that preconditions of nonpublic methods have been violated.


C, D.

Note

The purpose of IllegalArgumentException is to indicate a precondition violation in a public method. The core Java classes use it this way, and so should we.

The JVM does not throw IllegalArgumentException.




PreviousNext

Related