SCJP 5.0 About Exceptions

Here's an exercise from a book?

How is IllegalArgumentException used? (Choose all correct options.)

A. It is thrown by the JVM when a method is called with incompatible argument types.

B. It is thrown by the JVM to indicate arithmetic overflow.

C. It is thrown by certain methods of certain core Java classes to indicate that preconditions have been violated.

D. It should be used by programmers to indicate that preconditions of public methods have been violated.

E. It should be used by programmers to indicate that preconditions of nonpublic methods have been violated.

The correct answers are C and D. But in my opinion, A and E seems to be correct too. Is a RuntimeException the same as "the JVM" throw the exception? Can someone give its opinion?

[802 byte] By [blutch009a] at [2007-11-27 5:56:17]
# 1

A is not a correct option because the JVM does not throw this exception for incompatible arguments. It will throw some subclass of java.lang.Error

The option E sounds incorrect to me because preconditions for non-public methods should not be generating Runtime exceptions, in my opinion. Those should be handled by the methods using them.

aniseeda at 2007-7-12 16:26:38 > top of Java-index,Java Essentials,Training...
# 2

option E is quite possible, and pre 1.4 would have been certainly correct.

Now though it would be preferred to use assertions for parameter checking to non-public methods instead of IllegalArgumentException if and when you can run your system with assertions enabled during test/development.

jwentinga at 2007-7-12 16:26:38 > top of Java-index,Java Essentials,Training...