Consider this pair of Throwable
:
IllegalAccessException
extends Exception
Thrown when an application tries to reflectively create an instance (other than an array), set or get a field, or invoke a method, but the currently executing method does not have access to the definition of the specified class, field, method or constructor.
IllegalAccessError
ext IncompatibleClassChangeError ext LinkageError ext Error
Thrown if an application attempts to access or modify a field, or to call a method that it does not have access to.
Normally, this error is caught by the compiler; this error can only occur at run time if the definition of a class has incompatibly changed.
Questions
- Can someone give a code example where each is thrown?
- Does the similarity in name imply relationship between the two, or is it just pure coincidence?
- Are there other
XXXError
andXXXException
combo? How are the pairs related to each other? - If you explicitly
try
tocatch
one in anException/Error
pair, should you alsocatch
the other?